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 = 2e5 + 9;
const int M = 1e2 + 9;
int root[M];
int ls[N << 5], rs[N << 5];
int a[N];
int n, m, top;
int ans[N];
int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 1) + (x << 3) + (s ^ '0');
    s = getchar();
  }
  return f * 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 build(int &rt, int l, int r, int pos) {
  if (!rt) rt = ++top;
  if (l == r) return;
  if (pos <= ((l + r) >> 1))
    build(ls[rt], l, ((l + r) >> 1), pos);
  else
    build(rs[rt], ((l + r) >> 1) + 1, r, pos);
}
void update(int &x, int &y, int l, int r, int L, int R) {
  if (!x) return;
  if (L <= l && r <= R) {
    y = merge(x, y);
    x = 0;
    return;
  }
  if (!y) y = ++top;
  if (L <= ((l + r) >> 1)) update(ls[x], ls[y], l, ((l + r) >> 1), L, R);
  if (R > ((l + r) >> 1)) update(rs[x], rs[y], ((l + r) >> 1) + 1, r, L, R);
}
void search(int rt, int l, int r, int val) {
  if (!rt) return;
  if (l == r) {
    ans[l] = val;
    return;
  }
  search(ls[rt], l, ((l + r) >> 1), val);
  search(rs[rt], ((l + r) >> 1) + 1, r, val);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int val = read();
    build(root[val], 1, n, i);
  }
  m = read();
  while (m--) {
    int l = read();
    int r = read();
    int x = read();
    int y = read();
    if (x == y) continue;
    update(root[x], root[y], 1, n, l, r);
  }
  for (int i = 1; i <= 100; i++) search(root[i], 1, n, i);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
