import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m="";
int cases=Integer.parseInt(br.readLine());
for (int i = 0; i < cases; i++) {
br.readLine();
if(i>0)
sb.append("\n");
m=br.readLine();
charFreq []arr1=new charFreq[52];
for(int j=0;j<26;j++){
arr1[j]=new charFreq((char)('a'+j), 0);
arr1[j+26]=new charFreq((char)('A'+j), 0);
}
for(int j=0;j<m.length();j++){
if(m.charAt(j)>='a'&&m.charAt(j)<='z'){
arr1[m.charAt(j)-'a'].inc();
}else if(m.charAt(j)>='A'&&m.charAt(j)<='Z'){
arr1[m.charAt(j)-'A'+26].inc();
}
}
Arrays.sort(arr1);
m=br.readLine();
charFreq []arr2=new charFreq[52];
for(int j=0;j<26;j++){
arr2[j]=new charFreq((char)('a'+j), 0);
arr2[j+26]=new charFreq((char)('A'+j), 0);
}
for(int j=0;j<m.length();j++){
if(m.charAt(j)>='a'&&m.charAt(j)<='z'){
arr2[m.charAt(j)-'a'].inc();
}else if(m.charAt(j)>='A'&&m.charAt(j)<='Z'){
arr2[m.charAt(j)-'A'+26].inc();
}
}
Arrays.sort(arr2);
HashMap<Integer,Integer> hm=new HashMap<Integer, Integer>();
for(int j=arr1.length-1;j>-1;j--){
hm.put((int)(arr2[j].getC()),(int) (arr1[j].getC()));
}
for(int j=0;j<m.length();j++){
int temp=(hm.get((int)(m.charAt(j))));
char x=(char) temp;
sb.append(x);
}
sb.append("\n");
}
System.out.print(sb);
}
}
/*
}
}
}*/
class charFreq implements Comparable<charFreq> {
char c;
int freq;
public charFreq(char c, int freq) {
this.c = c;
this.freq = freq;
}
public char getC() {
return c;
}
public int getFreq() {
return freq;
}
public void inc(){
freq++;
}
@Override
public int compareTo(charFreq o) {
if(this.freq>o.getFreq()){
return 1;
}
return -1;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m="";
int cases=Integer.parseInt(br.readLine());
for (int i = 0; i < cases; i++) {
br.readLine();
if(i>0)
sb.append("\n");
m=br.readLine();
charFreq []arr1=new charFreq[52];
for(int j=0;j<26;j++){
arr1[j]=new charFreq((char)('a'+j), 0);
arr1[j+26]=new charFreq((char)('A'+j), 0);
}
for(int j=0;j<m.length();j++){
if(m.charAt(j)>='a'&&m.charAt(j)<='z'){
arr1[m.charAt(j)-'a'].inc();
}else if(m.charAt(j)>='A'&&m.charAt(j)<='Z'){
arr1[m.charAt(j)-'A'+26].inc();
}
}
Arrays.sort(arr1);
m=br.readLine();
charFreq []arr2=new charFreq[52];
for(int j=0;j<26;j++){
arr2[j]=new charFreq((char)('a'+j), 0);
arr2[j+26]=new charFreq((char)('A'+j), 0);
}
for(int j=0;j<m.length();j++){
if(m.charAt(j)>='a'&&m.charAt(j)<='z'){
arr2[m.charAt(j)-'a'].inc();
}else if(m.charAt(j)>='A'&&m.charAt(j)<='Z'){
arr2[m.charAt(j)-'A'+26].inc();
}
}
Arrays.sort(arr2);
HashMap<Integer,Integer> hm=new HashMap<Integer, Integer>();
for(int j=arr1.length-1;j>-1;j--){
hm.put((int)(arr2[j].getC()),(int) (arr1[j].getC()));
}
for(int j=0;j<m.length();j++){
int temp=(hm.get((int)(m.charAt(j))));
char x=(char) temp;
sb.append(x);
}
sb.append("\n");
}
System.out.print(sb);
}
}
/*
}
}
}*/
class charFreq implements Comparable<charFreq> {
char c;
int freq;
public charFreq(char c, int freq) {
this.c = c;
this.freq = freq;
}
public char getC() {
return c;
}
public int getFreq() {
return freq;
}
public void inc(){
freq++;
}
@Override
public int compareTo(charFreq o) {
if(this.freq>o.getFreq()){
return 1;
}
return -1;
}
}
No comments:
Post a Comment