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;
short tr[1 << 19][101];
bool lz[1 << 19];
short a[N];
void push(int v, int l, int r) {
  if (lz[v]) {
    if (l != r) {
      int v1 = v << 1;
      int v2 = v1 | 1;
      for (int i = 0; i <= 100; i++) {
        tr[v1][i] = tr[v][tr[v1][i]];
        tr[v2][i] = tr[v][tr[v2][i]];
      }
      lz[v1] = true;
      lz[v2] = true;
      for (int i = 0; i <= 100; i++) {
        tr[v][i] = i;
      }
    }
    lz[v] = false;
  }
}
void build(int v, int l, int r) {
  lz[v] = false;
  for (int i = 0; i <= 100; i++) {
    tr[v][i] = i;
  }
  if (l == r) return;
  int m = (l + r) >> 1;
  build(2 * v, l, m);
  build(2 * v + 1, m + 1, r);
}
void update(int v, int s, int e, int l, int r, int x, int y) {
  push(v, s, e);
  if (l <= s && e <= r) {
    for (int i = 0; i <= 100; i++) {
      if (tr[v][i] == x) {
        tr[v][i] = y;
      }
    }
    lz[v] = true;
    return;
  }
  if (e < l || r < s || r < l) return;
  int m = (s + e) >> 1;
  update(2 * v, s, m, l, r, x, y);
  update(2 * v + 1, m + 1, e, l, r, x, y);
}
void dfs(int v, int l, int r) {
  push(v, l, r);
  if (l == r) {
    a[l] = tr[v][a[l]];
    return;
  }
  int m = (l + r) >> 1;
  dfs(2 * v, l, m);
  dfs(2 * v + 1, m + 1, r);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(32);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  int q;
  cin >> q;
  int l, r, x, y;
  while (q--) {
    cin >> l >> r >> x >> y;
    update(1, 1, n, l, r, x, y);
  }
  dfs(1, 1, n);
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << '\n';
  return 0;
}
