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;
template <class T>
class segment_tree {
 private:
  int N;
  vector<pair<vector<T>, bool> > val;
  void push_down(int root) {
    if (val[root].second) {
      for (int i = 1; i <= 100; i++) {
        val[root << 1].first[i] = val[root].first[val[root << 1].first[i]];
        val[root << 1 | 1].first[i] =
            val[root].first[val[root << 1 | 1].first[i]];
      }
      for (int i = 1; i <= 100; i++) val[root].first[i] = i;
      val[root << 1].second = true;
      val[root << 1 | 1].second = true;
      val[root].second = false;
    }
  }
  void build(int root, int istart, int iend) {
    for (int i = 1; i <= 100; i++) val[root].first[i] = i;
    if (istart != iend) {
      int mid = (istart + iend) >> 1;
      build(root << 1, istart, mid);
      build(root << 1 | 1, mid + 1, iend);
    }
  }
  void query(int root, int istart, int iend, vector<T>& a) {
    if (istart == iend) {
      a[istart] = val[root].first[a[istart]];
      return;
    }
    push_down(root);
    int mid = (istart + iend) >> 1;
    query(root << 1, istart, mid, a);
    query(root << 1 | 1, mid + 1, iend, a);
  }
  void update(int root, int istart, int iend, int ustart, int uend, const T& x,
              const T& y) {
    if (ustart > iend || uend < istart) return;
    if (ustart <= istart && uend >= iend) {
      for (int i = 1; i <= 100; i++)
        if (val[root].first[i] == x) val[root].first[i] = y;
      val[root].second = true;
      return;
    }
    push_down(root);
    int mid = (istart + iend) >> 1;
    update(root << 1, istart, mid, ustart, uend, x, y);
    update(root << 1 | 1, mid + 1, iend, ustart, uend, x, y);
  }

 public:
  segment_tree(int n) : N(n), val(N << 2, make_pair(vector<T>(101), 0)) {
    build(1, 1, N);
  }
  void query(vector<T>& a) { query(1, 1, N, a); }
  void update(int l, int r, const T& x, const T& y) {
    update(1, 1, N, l, r, x, y);
  }
};
int main() {
  int n, m, l, r, x, y;
  while (~scanf("%d", &n)) {
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    segment_tree<int> st = n;
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d%d", &l, &r, &x, &y);
      st.update(l, r, x, y);
    }
    st.query(a);
    for (int i = 1; i <= n; i++) {
      if (i != 1) printf(" ");
      printf("%d", a[i]);
    }
    printf("\n");
  }
  return 0;
}
