#include<iostream>
using namespace std;
int main() {
	int n, m;
	char data[100][2], str[100000];
	while (cin >> n && n) {
		for (int i = 0; i < n; ++i) cin >> data[i][0] >> data[i][1];
		cin >> m;
		for (int i = 0; i < m; ++i) {
			cin >> str[i];
			for (int j = 0; j < n; ++j) {
				if (str[i] == data[j][0]) {
					str[i] = data[j][1];
					break;
				}
			}
		}
		for (int i = 0; i < m; ++i) cout << str[i];
		cout << endl;
	}
	return 0;
}
