#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &it : a) cin >> it;
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) a[i] = c;
    }
    for (int &it : a) cout << it << " ";
    cout << "\n";
  }
  return 0;
}
