#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int n,m;
	int henkan[256];
	while(cin>>n,n){
		memset(henkan,0,sizeof(henkan));
		while(n--){
			char a,b; cin>>a>>b;
			henkan[(int)a] = b;
		}
		cin>>m;
		while(m--){
			char a; cin>>a;
			printf("%c",henkan[(int)a]?:a);
		}
		puts("");
	}
	return 0;
}