// Arup Guha
// 6/20/2025
// Solution to Translation
// https://open.kattis.com/problems/translation

using namespace std;
#include <bits/stdc++.h>

int main() {

    // Read in the sentence to translate.
    int n;
    cin >> n;
    vector<string> words(n);
    for (int i=0; i<n; i++)
        cin >> words[i];

    // Read in the dictionary into a map.
    map<string,string> dictionary;
    int m;
    cin >> m;
    for (int i=0; i<m; i++) {
        string foreign, english;
        cin >> foreign >> english;
        dictionary[foreign] = english;
    }

    // Translate!
    for (int i=0; i<n; i++)
        cout << dictionary[words[i]] << " ";
    cout << endl;

    return 0;
}
