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 = 1e7 + 5;
const int MAXM = 105;
int st[MAXN], top, tree_cnt;
int ls[MAXN], rs[MAXN], rt[MAXM], val[200005];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
inline int get() { return top ? st[top--] : ++tree_cnt; }
void modify(int l, int r, int p, int &cur) {
  if (!cur) cur = ++tree_cnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid)
    modify(l, mid, p, ls[cur]);
  else
    modify(mid + 1, r, p, rs[cur]);
}
void merge(int &x, int &y) {
  if (!x || !y) return x |= y, y = 0, void();
  merge(ls[x], ls[y]), merge(rs[x], rs[y]), st[++top] = y, y = 0;
}
void change(int l, int r, int ql, int qr, int &pre, int &cur) {
  if (!pre) return;
  if (ql <= l && qr >= r) return merge(cur, pre);
  if (!cur) cur = get();
  int mid = (l + r) >> 1;
  if (ql <= mid) change(l, mid, ql, qr, ls[pre], ls[cur]);
  if (qr > mid) change(mid + 1, r, ql, qr, rs[pre], rs[cur]);
  if (!ls[pre] && !rs[pre]) st[++top] = pre, pre = 0;
}
void dfs(int l, int r, int cur, int c) {
  if (!cur) return;
  if (l == r) return val[l] = c, void();
  int mid = (l + r) >> 1;
  dfs(l, mid, ls[cur], c);
  dfs(mid + 1, r, rs[cur], c);
}
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) modify(1, n, i, rt[read()]);
  int m = read();
  for (int i = 1; i <= m; i++) {
    int l = read(), r = read();
    int x = read(), y = read();
    if (x == y) continue;
    change(1, n, l, r, rt[x], rt[y]);
  }
  for (int i = 1; i <= 100; i++) dfs(1, n, rt[i], i);
  for (int i = 1; i <= n; i++) printf("%d%c", val[i], " \n"[i == n]);
  return 0;
}
