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 + 100;
int n, q;
int a[N];
int tree[3 * N][101];
void build(int tl = 1, int tr = n, int td = 1) {
  if (tl > tr) return;
  for (int i = 1; i <= 100; i++) tree[td][i] = i;
  if (tl == tr) return;
  int tm = (tl + tr) >> 1;
  build(tl, tm, (td << 1));
  build(tm + 1, tr, (td << 1) + 1);
}
void push(int td) {
  for (int i = 1; i <= 100; i++) {
    tree[(td << 1)][i] = tree[td][tree[(td << 1)][i]];
    tree[(td << 1) + 1][i] = tree[td][tree[(td << 1) + 1][i]];
  }
  for (int i = 1; i <= 100; i++) tree[td][i] = i;
}
void update(int l, int r, int x, int y, int tl = 1, int tr = n, int td = 1) {
  if (tl > tr || tr < l || r < tl) return;
  if (l <= tl && tr <= r) {
    for (int i = 1; i <= 100; i++)
      if (tree[td][i] == x) tree[td][i] = y;
    return;
  }
  if (tl != tr) push(td);
  int tm = (tl + tr) >> 1;
  update(l, r, x, y, tl, tm, (td << 1));
  update(l, r, x, y, tm + 1, tr, (td << 1) + 1);
}
void afterqueries(int tl = 1, int tr = n, int td = 1) {
  if (tl > tr) return;
  if (tl == tr) {
    a[tl] = tree[td][a[tl]];
    return;
  }
  push(td);
  int tm = (tl + tr) >> 1;
  afterqueries(tl, tm, (td << 1));
  afterqueries(tm + 1, tr, (td << 1) + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build();
  cin >> q;
  while (q--) {
    int l, r, x, y;
    cin >> l >> r >> x >> y;
    update(l, r, x, y);
  }
  afterqueries();
  for (int i = 1; i <= n; i++) cout << a[i] << ' ';
}
