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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("avx")
using namespace std;
constexpr int MAX_N = 1 << 18;
constexpr int BUF_SIZE = 16 << 20;
char input[BUF_SIZE], output[BUF_SIZE];
int nIn, nOut;
char elems[MAX_N];
inline __attribute__((always_inline)) int getUint() {
  int n = 0, chr = input[nIn++];
  while (chr == '\n' || chr == ' ') chr = input[nIn++];
  do {
    n = n * 10 + chr - '0';
    chr = input[nIn++];
  } while (chr != '\n' && chr != ' ');
  return n;
}
inline __attribute__((always_inline)) void putUint(int n) {
  char str[10];
  int i = 0;
  while (n > 0) {
    str[i++] = char((n % 10) + '0');
    n /= 10;
  }
  while (--i >= 0) output[nOut++] = str[i];
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  fread(input, 1, BUF_SIZE, stdin);
  int n, q, l, r;
  char x, y;
  n = getUint();
  for (int i = 0; i < n; i++) elems[i] = char(getUint());
  q = getUint();
  while (q--) {
    l = getUint() - 1;
    r = getUint();
    x = char(getUint());
    y = char(getUint());
    while ((l & 0xF) && l < r) {
      if (elems[l] == x) elems[l] = y;
      l++;
    }
    for (; l < r; l++)
      if (elems[l] == x) elems[l] = y;
  }
  for (int i = 0; i < n; i++) {
    putUint(elems[i]);
    output[nOut++] = ' ';
  }
  output[nOut++] = '\n';
  fwrite(output, 1, nOut, stdout);
  fflush(stdout);
  return 0;
}
