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;
int ls[500007 * 10], rs[500007 * 10], root[500007 * 10], a[500007];
int n, x, l, r, y, Q, cnt = 0;
void insert(int &k, int l, int r, int x) {
  if (!k) k = ++cnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    insert(ls[k], l, mid, x);
  else if (x > mid)
    insert(rs[k], mid + 1, r, x);
}
int merge(int x, int y) {
  if (!x) return y;
  if (!y) return x;
  ls[x] = merge(ls[x], ls[y]);
  rs[x] = merge(rs[x], rs[y]);
  return x;
}
void change(int &k, int &last, int l, int r, int x, int y) {
  if (!last) return;
  if (x <= l && y >= r) {
    k = merge(k, last);
    last = 0;
    return;
  }
  if (!k) k = ++cnt;
  int mid = (l + r) >> 1;
  if (x <= mid) change(ls[k], ls[last], l, mid, x, y);
  if (y > mid) change(rs[k], rs[last], mid + 1, r, x, y);
}
void dfs(int k, int l, int r, int x) {
  if (!k) return;
  if (l == r) {
    a[l] = x;
    return;
  }
  int mid = (l + r) >> 1;
  dfs(ls[k], l, mid, x);
  dfs(rs[k], mid + 1, r, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    insert(root[x], 1, n, i);
  }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d%d%d", &l, &r, &x, &y);
    if (x == y) continue;
    change(root[y], root[x], 1, n, l, r);
  }
  for (int i = 1; i <= 100; i++) dfs(root[i], 1, n, i);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
