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>
struct Data {
  int val;
  int laz[101];
};
struct SegmentTree {
  std::vector<Data> s;
  SegmentTree(int n) : s(n << 2) {}
  void build(int rt, int L, int R) {
    for (int i = 1; i <= 100; i++) s[rt].laz[i] = i;
    if (L == R) return (void)(std::cin >> s[rt].val);
    int mid = (L + R) >> 1;
    build(rt << 1, L, mid);
    build(rt << 1 | 1, mid + 1, R);
  }
  void pushdown(int rt) {
    for (int i = 1; i <= 100; i++) {
      s[rt << 1].laz[i] = s[rt].laz[s[rt << 1].laz[i]];
      s[rt << 1 | 1].laz[i] = s[rt].laz[s[rt << 1 | 1].laz[i]];
    }
    for (int i = 1; i <= 100; i++) s[rt].laz[i] = i;
    return;
  }
  void update(int rt, int L, int R, int l, int r, int x, int y) {
    if (l <= L && R <= r) {
      for (int i = 1; i <= 100; i++)
        if (s[rt].laz[i] == x) s[rt].laz[i] = y;
      return;
    }
    pushdown(rt);
    int mid = (L + R) >> 1;
    if (l <= mid) update(rt << 1, L, mid, l, r, x, y);
    if (r > mid) update(rt << 1 | 1, mid + 1, R, l, r, x, y);
  }
  void print(int rt, int L, int R) {
    if (L == R) return void(std::cout << s[rt].laz[s[rt].val] << ' ');
    pushdown(rt);
    int mid = (L + R) >> 1;
    print(rt << 1, L, mid);
    print(rt << 1 | 1, mid + 1, R);
  }
};
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int n;
  std::cin >> n;
  SegmentTree segt(n);
  segt.build(1, 1, n);
  int m;
  std::cin >> m;
  while (m--) {
    int l, r, x, y;
    std::cin >> l >> r >> x >> y;
    segt.update(1, 1, n, l, r, x, y);
  }
  segt.print(1, 1, n);
  return 0;
}
