#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int q; cin >> q;
  vector<vector<int>> data(q,vector<int>(2));
  rep(i,q){
    rep(j,2){
      cin >> data[i][j];
      if(data[i]==a[i]) a[i]=data[j];
    }
  }
  rep(i,n) cout << a[i] << endl;
  return 0;
}
