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 n;
int a[200010];
const int sz = 1 << 18;
char t[2 * sz][101];
vector<int> pos[200010], xx[200010], yy[200010];
void update(int v, int vl, int vr, int pos, int x, int y) {
  t[pos + sz][x] = y;
  pos = (pos + sz) >> 1;
  for (; pos > 0; pos >>= 1) {
    int l = pos << 1;
    int r = l | 1;
    for (int i = 1; i <= 100; i++) {
      t[pos][i] = t[r][t[l][i]];
    }
  }
}
int main() {
  for (int i = 0; i < 2 * sz; i++) {
    for (int j = 1; j <= 100; j++) {
      t[i][j] = j;
    }
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int l, r, x, y;
    scanf("%d%d%d%d", &l, &r, &x, &y);
    l--, r--;
    pos[l].push_back(i), pos[r + 1].push_back(i);
    xx[l].push_back(x), xx[r + 1].push_back(x);
    yy[l].push_back(y), yy[r + 1].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int)pos[i].size(); j++) {
      update(1, 0, n - 1, pos[i][j], xx[i][j], yy[i][j]);
    }
    printf("%d ", (int)t[1][a[i]]);
  }
}
