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 = 2000007;
struct node {
  int l, r;
  int s;
};
int a[N];
int sets[107];
node seg[N];
queue<int> garbage;
int tt;
int new_node() {
  int u;
  if (garbage.size())
    u = garbage.front(), garbage.pop();
  else
    u = ++tt;
  seg[u].l = seg[u].r = seg[u].s = 0;
  return u;
}
void add(int& cur, int l, int r, int j, int x) {
  if (cur == 0) cur = new_node();
  if (l == r) {
    seg[cur].s += x;
  } else {
    if (j <= ((l + r) >> 1))
      add(seg[cur].l, l, ((l + r) >> 1), j, x);
    else
      add(seg[cur].r, ((l + r) >> 1) + 1, r, j, x);
    seg[cur].s = (seg[cur].l ? seg[seg[cur].l].s : 0) +
                 (seg[cur].r ? seg[seg[cur].r].s : 0);
  }
}
inline int sz(int x) { return x == 0 ? 0 : seg[x].s; }
void split(int t1, int& t2, int l, int r, int x) {
  if (!t1) return;
  t2 = new_node();
  if (((l + r) >> 1) == x) {
    swap(seg[t1].r, seg[t2].r);
  } else if (((l + r) >> 1) < x) {
    split(seg[t1].r, seg[t2].r, ((l + r) >> 1) + 1, r, x);
  } else {
    swap(seg[t1].r, seg[t2].r);
    split(seg[t1].l, seg[t2].l, l, ((l + r) >> 1), x);
  }
  if (l == r) {
    if (x < ((l + r) >> 1)) swap(seg[t1].s, seg[t2].s);
  } else {
    seg[t1].s =
        (seg[t1].l ? seg[seg[t1].l].s : 0) + (seg[t1].r ? seg[seg[t1].r].s : 0);
    seg[t2].s =
        (seg[t2].l ? seg[seg[t2].l].s : 0) + (seg[t2].r ? seg[seg[t2].r].s : 0);
  }
}
void merge(int& t1, int t2) {
  if (!t1 or !t2) return void(t1 = (t1 ? t1 : t2));
  merge(seg[t1].l, seg[t2].l);
  merge(seg[t1].r, seg[t2].r);
  seg[t1].s += seg[t2].s;
  garbage.push(t2);
}
void go(int cur, int l, int r, int val = 0) {
  if (!cur) return;
  if (l == r) {
    if (seg[cur].s) {
      if (val == 0)
        cout << l << ' ';
      else
        a[l] = val;
    }
  } else {
    go(seg[cur].l, l, ((l + r) >> 1), val);
    go(seg[cur].r, ((l + r) >> 1) + 1, r, val);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    add(sets[a[i]], 1, n, i, 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r, x, y;
    cin >> l >> r >> x >> y;
    int aux1 = 0, aux2 = 0;
    split(sets[x], aux1, 1, n, l - 1);
    split(aux1, aux2, 1, n, r);
    merge(sets[x], aux2);
    merge(sets[y], aux1);
  }
  for (int i = 1; i <= 100; ++i) {
    go(sets[i], 1, n, i);
  }
  for (int i = 1; i <= n; ++i) cout << a[i] << ' ';
  cout << '\n';
}
