import java.io.*;
import java.util.*;

public class conspiracy_ats implements Runnable {
	public static void main(String[] args) {
		new Thread(new conspiracy_ats()).start();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int n = nextInt();
		assert (1 <= n && n <= (int) 1e5);

		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = nextToken();
			for (int j = 0; j < s[i].length(); j++) {
				assert ('a' <= s[i].charAt(j) && s[i].charAt(j) <= 'z');
			}
		}
		char[] was = new char[26];
		for (int i = 0; i < 26; i++) {
			char u = nextToken().charAt(0);
			char v = nextToken().charAt(0);
			was[(int) (v - 'a')] = u;
		}
		String[] original = new String[n];
		for (int i = 0; i < n; i++) {
			original[i] = "";
			for (int j = 0; j < s[i].length(); j++) {
				original[i] += was[(int) (s[i].charAt(j) - 'a')];
			}
		}
		Arrays.sort(original);
		out.println(original[0]);
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader("conspiracy.in"));
			out = new PrintWriter("conspiracy.out");

			solve();

			out.close();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
