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 = 200005;
int n, v[N], Q, a[N], b[N];
vector<int> v1[N], v2[N];
struct node {
  int a[105];
} t[1 << 19];
node operator+(node a, node b) {
  node ans;
  for (int i = (int)(1); i <= (int)(100); i++) ans.a[i] = b.a[a.a[i]];
  return ans;
}
void build(int k, int l, int r) {
  if (l == r) {
    for (int i = (int)(1); i <= (int)(100); i++) t[k].a[i] = i;
    return;
  }
  int mid = (l + r) / 2;
  build(k * 2, l, mid);
  build(k * 2 + 1, mid + 1, r);
  t[k] = t[k * 2] + t[k * 2 + 1];
}
void change(int k, int l, int r, int p, int v1, int v2) {
  if (l == r) {
    t[k].a[v1] = v2;
    return;
  }
  int mid = (l + r) / 2;
  if (p <= mid)
    change(k * 2, l, mid, p, v1, v2);
  else
    change(k * 2 + 1, mid + 1, r, p, v1, v2);
  t[k] = t[k * 2] + t[k * 2 + 1];
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &v[i]);
  scanf("%d", &Q);
  for (int i = (int)(1); i <= (int)(Q); i++) {
    int l, r;
    scanf("%d%d%d%d", &l, &r, &a[i], &b[i]);
    v1[l].push_back(i);
    v2[r + 1].push_back(i);
  }
  build(1, 1, Q);
  for (int i = (int)(1); i <= (int)(n); i++) {
    for (auto j : v1[i]) change(1, 1, Q, j, a[j], b[j]);
    for (auto j : v2[i]) change(1, 1, Q, j, a[j], a[j]);
    v[i] = t[1].a[v[i]];
  }
  for (int i = (int)(1); i <= (int)(n); i++) printf("%d ", v[i]);
}
