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 MAXN = 200000 + 10;
const int MAXA = 101;
const int MAXPL = MAXN * 80;
const char ENDLINE = '\n';
int ls[MAXPL], rs[MAXPL];
int alloc;
int rt[MAXN], n;
void add(int& o, int l, int r, int x) {
  if (!o) o = ++alloc;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    add(ls[o], l, mid, x);
  else
    add(rs[o], mid + 1, r, x);
}
void merge(int& o, int& p, int L, int R, int l, int r) {
  if (o == p) return;
  if (L == l && R == r) {
    if (!o || !p) {
      o = o + p;
    } else {
      int mid = (L + R) >> 1;
      merge(ls[o], ls[p], L, mid, l, mid);
      merge(rs[o], rs[p], mid + 1, R, mid + 1, r);
    }
    p = 0;
  } else {
    if (!p) return;
    if (!o) o = ++alloc;
    int mid = (L + R) >> 1;
    if (r <= mid)
      merge(ls[o], ls[p], L, mid, l, r);
    else if (mid < l)
      merge(rs[o], rs[p], mid + 1, R, l, r);
    else
      merge(ls[o], ls[p], L, mid, l, mid),
          merge(rs[o], rs[p], mid + 1, R, mid + 1, r);
  }
}
void traverse(int o, int l, int r, int a[], int x) {
  if (!o) return;
  if (l == r) {
    a[l] = x;
    return;
  }
  int mid = (l + r) >> 1;
  traverse(ls[o], l, mid, a, x);
  traverse(rs[o], mid + 1, r, a, x);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    add(rt[x], 1, n, i);
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int l, r, x, v;
    cin >> l >> r >> x >> v;
    merge(rt[v], rt[x], 1, n, l, r);
  }
  static int a[MAXN];
  for (int i = 0; i < MAXA; ++i) {
    traverse(rt[i], 1, n, a, i);
  }
  for (int i = 1; i <= n; ++i) cout << a[i] << ENDLINE;
}
