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[202020];
int seg[(1 << 18) * 2][101];
void push(int k) {
  if (k < (1 << 18) - 1) {
    for (long long i = (long long)(0); i < (long long)(100); i++) {
      seg[k * 2 + 1][i] = seg[k][seg[k * 2 + 1][i]];
      seg[k * 2 + 2][i] = seg[k][seg[k * 2 + 2][i]];
    }
  }
  for (long long i = (long long)(0); i < (long long)(100); i++) seg[k][i] = i;
}
void update(int a, int b, int x, int y, int k = 0, int l = 0,
            int r = (1 << 18)) {
  if (a >= r || b <= l)
    return;
  else if (a <= l && r <= b) {
    for (long long i = (long long)(0); i < (long long)(100); i++)
      if (seg[k][i] == x) seg[k][i] = y;
    return;
  }
  push(k);
  update(a, b, x, y, k * 2 + 1, l, (l + r) / 2);
  update(a, b, x, y, k * 2 + 2, (l + r) / 2, r);
}
int main() {
  scanf("%d", &n);
  for (long long i = (long long)(0); i < (long long)(n); i++)
    scanf("%d", a + i);
  for (long long i = (long long)(0); i < (long long)((1 << 18) * 2); i++)
    for (long long j = (long long)(0); j < (long long)(100); j++) seg[i][j] = j;
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r, x, y;
    scanf("%d%d%d%d", &l, &r, &x, &y);
    l--;
    x--;
    y--;
    update(l, r, x, y);
  }
  for (long long i = (long long)(0); i < (long long)((1 << 18) - 1); i++)
    push(i);
  for (long long i = (long long)(0); i < (long long)(n); i++)
    printf("%d ", seg[i + (1 << 18) - 1][a[i] - 1] + 1);
  printf("\n");
  return 0;
}
