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;
int arr[200005];
struct trie {
  struct trie *left;
  struct trie *right;
  int nodes;
  trie() {
    left = NULL;
    right = NULL;
    nodes = 0;
  }
};
struct trie *root[105];
void insert(struct trie *&curr, int start, int end, int idx) {
  if (curr == NULL) curr = new trie, curr->nodes = 1;
  if (start != end) {
    int mid = (start + end) / 2;
    if (idx <= mid)
      insert(curr->left, start, mid, idx);
    else
      insert(curr->right, mid + 1, end, idx);
  }
}
void update(struct trie *&curr1, struct trie *&curr2, int start, int end, int l,
            int r) {
  if (end < l || start > r) return;
  if (curr1 == NULL) return;
  if (start == end) {
    curr2 = new trie;
    curr2->nodes = 1;
    delete curr1;
    curr1 = NULL;
    return;
  }
  int mid = (start + end) / 2;
  if (l <= start && end <= r) {
    if (curr2 == NULL) {
      swap(curr1, curr2);
      return;
    }
  }
  if (curr2 == NULL) curr2 = new trie;
  curr2->nodes = 1;
  update(curr1->left, curr2->left, start, mid, l, r);
  update(curr1->right, curr2->right, mid + 1, end, l, r);
  long long int val = 0;
  if (curr1->left != NULL) val++;
  if (curr1->right != NULL) val++;
  if (val == 0) {
    delete curr1;
    curr1 = NULL;
  }
}
void dfs(struct trie *&curr, int start, int end, int value) {
  if (curr == NULL) return;
  if (start != end) {
    int mid = (start + end) / 2;
    if (curr->left != NULL) dfs(curr->left, start, mid, value);
    if (curr->right != NULL) dfs(curr->right, mid + 1, end, value);
  } else {
    arr[start] = value;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 103; i++) root[i] = NULL;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    insert(root[a], 1, n, i);
  }
  long long int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    int x;
    int y;
    cin >> x >> y;
    if (x != y) update(root[x], root[y], 1, n, l, r);
  }
  for (int i = 1; i <= 100; i++) dfs(root[i], 1, n, i);
  for (int i = 1; i <= n; i++) cout << arr[i] << " ";
  cout << '\n';
}
