You are given an array a consisting of n integers. You have to process q queries to this array; each query is given as four numbers l, r, x and y, denoting that for every i such that l ≤ i ≤ r and ai = x you have to set ai equal to y.

Print the array after all queries are processed.

Input

The first line contains one integer n (1 ≤ n ≤ 200000) — the size of array a.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the elements of array a.

The third line contains one integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow. i-th line contains four integers l, r, x and y denoting i-th query (1 ≤ l ≤ r ≤ n, 1 ≤ x, y ≤ 100).

Output

Print n integers — elements of array a after all changes are made.

Example

Input

5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5


Output

5 2 5 4 5 
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
int binpow(int b, int p, int mod) {
  int ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
int n;
short t[800800][101];
void build(int id, int l, int r) {
  for (short i = 1; i <= 100; i++) t[id][i] = i;
  if (l == r) return;
  build(id << 1, l, ((l + r) >> 1));
  build(id << 1 | 1, ((l + r) >> 1) + 1, r);
}
pair<int, int> qvals[200200];
void update(int id, int l, int r, int &pos, int &active) {
  if (pos < l || pos > r) return;
  if (l == r) {
    if (active) {
      t[id][qvals[l].first] = qvals[l].second;
    } else {
      t[id][qvals[l].first] = qvals[l].first;
    }
    return;
  }
  update(id << 1, l, ((l + r) >> 1), pos, active);
  update(id << 1 | 1, ((l + r) >> 1) + 1, r, pos, active);
  for (int i = 1; i <= 100; ++i) {
    t[id][i] = t[id << 1 | 1][t[id << 1][i]];
  }
}
vector<pair<int, int> > qoffline[200200];
int vals[200200];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> vals[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int l, r, x, y;
    cin >> l >> r >> x >> y;
    qvals[i] = make_pair(x, y);
    qoffline[l].emplace_back(i, 1);
    qoffline[r + 1].emplace_back(i, 0);
  }
  build(1, 0, q);
  for (int i = 1; i <= n; ++i) {
    for (auto &v : qoffline[i]) {
      update(1, 0, q, v.first, v.second);
    }
    vals[i] = t[1][vals[i]];
  }
  for (int i = 1; i <= n; ++i) {
    cout << vals[i] << " ";
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  int _t = 1;
  for (int i = 1; i <= _t; i++) {
    solve();
  }
}
