#include <iostream>
#include <map>

using namespace std;

int main ( void )
{
	int n;

	while ( cin >> n, n )
	{
		map<char, char> t;

		for (int i = 0; i < n; ++i)
		{
			char a, b;
			cin >> a >> b;
			t[a] = b;
		}

		int m;
		cin >> m;

		for (int i = 0; i < m; ++i)
		{
			char c;
			cin >> c;
			if ( t.count(c) )
				cout << t[c];
			else
				cout << c;
		}
		cout << endl;
	}

	return 0;
}