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 ans[200005];
int roots[105];
struct node {
  int l, r;
} tree[200005 * 20];
int cnt = 0;
void build(int &x, int pos, int l, int r) {
  if (!x) x = ++cnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    build(tree[x].l, pos, l, mid);
  else
    build(tree[x].r, pos, mid + 1, r);
}
int merge(int &x, int &y) {
  if (!x) return y;
  if (!y) return x;
  tree[y].l = merge(tree[x].l, tree[y].l);
  tree[y].r = merge(tree[x].r, tree[y].r);
  return y;
}
void modify(int &x, int &y, int l, int r, int posl, int posr) {
  if (!x) return;
  if (l >= posl && r <= posr) {
    y = merge(x, y);
    x = 0;
  }
  if (!y) y = ++cnt;
  int mid = (l + r) >> 1;
  if (posl <= mid) modify(tree[x].l, tree[y].l, l, mid, posl, posr);
  if (posr > mid) modify(tree[x].r, tree[y].r, mid + 1, r, posl, posr);
}
void get_ans(int pos, int num, int l, int r) {
  if (!pos) return;
  if (l == r) {
    ans[l] = num;
    return;
  }
  int mid = (l + r) >> 1;
  get_ans(tree[pos].l, num, l, mid);
  get_ans(tree[pos].r, num, mid + 1, r);
}
int main() {
  int n;
  scanf("%d", &n);
  int x;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    build(roots[x], i, 1, n);
  }
  int m;
  scanf("%d", &m);
  int l, r, y;
  while (m--) {
    scanf("%d%d%d%d", &l, &r, &x, &y);
    if (x == y) continue;
    modify(roots[x], roots[y], 1, n, l, r);
  }
  for (int i = 1; i <= 100; i++) {
    get_ans(roots[i], i, 1, n);
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
