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>
using namespace std;
const int N = 1 << 18;
int n, q, a[N];
vector<tuple<int, int, int> > queries[N];
struct node {
  int f[101];
  node() {
    for (int i = 1; i <= 100; i++) f[i] = i;
  }
  void update(int x, int y) { f[x] = y; }
} t[2 * N];
void merge(node& l, node& r, node& store) {
  node res;
  for (int i = 1; i <= 100; i++) {
    res.f[i] = r.f[l.f[i]];
  }
  store = res;
}
void update(int p, int x, int y) {
  t[p += N].update(x, y);
  for (p >>= 1; p >= 1; p >>= 1) {
    merge(t[p << 1], t[p << 1 | 1], t[p]);
  }
}
int query(int val) {
  int l = 0, r = N;
  node res;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l & 1) merge(res, t[l++], res);
    if (r & 1) merge(res, t[--r], res);
  }
  return res.f[val];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (int i = 0, l, r, x, y; i < q; i++) {
    cin >> l >> r >> x >> y;
    --l, --r;
    queries[r + 1].emplace_back(i, x, x);
    queries[l].emplace_back(i, x, y);
  }
  for (int i = 0; i < n; i++) {
    for (auto tt : queries[i]) {
      int curr_time, x, y;
      tie(curr_time, x, y) = tt;
      update(curr_time, x, y);
    }
    cout << query(a[i]) << ' ';
  }
}
