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 replace {
  unsigned int next[100];
  inline replace() {}
  inline replace(const replace& p) { memcpy(next, p.next, sizeof(next)); }
  inline unsigned int& operator[](unsigned int id) { return next[id]; }
  inline void operator*=(const replace& p) {
    for (register unsigned int i = 0; i < 100; ++i) next[i] = p.next[next[i]];
  }
} idnt;
struct READ {
  char c;
  inline READ() {
    for (register unsigned int i = 0; i < 100; ++i) idnt[i] = i;
    c = getchar();
  }
  template <typename type>
  inline READ& operator>>(register type& num) {
    while ('0' > c || c > '9') c = getchar();
    for (num = 0; '0' <= c && c <= '9'; c = getchar())
      num = num * 10 + (c - '0');
    return *this;
  }
} cin;
template <unsigned int size>
struct segment_tree {
  segment_tree<(size >> 1)> l, r;
  replace rep;
  unsigned char tag;
  inline segment_tree() : rep(idnt) {}
  inline void operator()(unsigned int f, unsigned int t, unsigned int x,
                         unsigned int y) {
    if (f == 0 && t == (size << 1) - 1) {
      for (register unsigned int i = 0; i < 100; ++i)
        if (rep[i] == x) rep[i] = y;
      return void(tag = 1);
    }
    if (tag) {
      l.rep *= rep, r.rep *= rep;
      rep = idnt, tag = 0, l.tag = r.tag = 1;
    }
    if (f & size)
      r(f & ~size, t & ~size, x, y);
    else if ((t & size) ^ size)
      l(f, t, x, y);
    else
      l(f, size - 1, x, y), r(0, t & ~size, x, y);
  }
  inline unsigned int operator()(unsigned int id, unsigned int x) {
    return rep[id & size ? r(id & ~size, x) : l(id, x)];
  }
};
template <>
struct segment_tree<0> {
  replace rep;
  unsigned char tag;
  inline segment_tree() : rep(idnt) {}
  inline void operator()(unsigned int f, unsigned int t, unsigned int x,
                         unsigned int y) {
    for (register unsigned int i = 0; i < 100; ++i)
      if (rep[i] == x) rep[i] = y;
  }
  inline unsigned int operator()(unsigned int id, unsigned int x) {
    return rep[x];
  }
};
segment_tree<(1 << 17)> tree;
unsigned int n, q, num[200010];
int main() {
  cin >> n;
  for (register unsigned int i = 0; i < n; ++i) cin >> num[i], --num[i];
  unsigned int l, r, x, y;
  for (cin >> q; q; --q) {
    cin >> l >> r >> x >> y;
    --l, --r, --x, --y;
    tree(l, r, x, y);
  }
  for (register unsigned int i = 0; i < n; ++i)
    printf("%u ", tree(i, num[i]) + 1);
  return 0;
}
