#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long inv[601010];
long long p[601010];
long long num[601010];
long long arr[601010];
long long find(long long x) {
  if (p[x] == x) return x;
  return p[x] = find(p[x]);
}
long long uni(long long a, long long b) {
  a = find(a);
  b = find(b);
  if (a == b) return a;
  if (num[a] > num[b]) swap(a, b);
  num[b] = num[a] + num[b];
  p[a] = b;
  return b;
}
void solve() {
  long long Q;
  cin >> Q;
  long long i;
  long long cnt = 0;
  long long t, a, b;
  for (i = 1; i <= Q; i++) {
    cin >> t >> a;
    if (t == 2) cin >> b;
    if (t == 1) {
      cnt++;
      p[cnt] = cnt;
      num[cnt] = 1;
      if (inv[a]) {
        p[cnt] = inv[a];
        num[inv[a]]++;
      } else {
        arr[cnt] = a;
        inv[a] = cnt;
      }
    } else {
      if (a == b) continue;
      if (inv[a] == 0) continue;
      if (inv[b]) {
        long long x = inv[a];
        long long y = inv[b];
        long long u = uni(x, y);
        inv[a] = 0;
        inv[b] = u;
        arr[u] = b;
      } else {
        long long x = inv[a];
        arr[x] = b;
        inv[a] = 0;
        inv[b] = x;
      }
    }
  }
  for (i = 1; i <= cnt; i++) {
    long long x = find(i);
    cout << arr[x] << ' ';
  }
  cout << '\n';
}
void init() {}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long long T;
  T = 1;
  while (T--) {
    init();
    solve();
  }
}

### Prompt

In Cpp, your task is to solve the following problem:

You have an array of integers (initially empty).

You have to perform q queries. Each query is of one of two types: 

  * "1 x" — add the element x to the end of the array; 
  * "2 x y" — replace all occurrences of x in the array with y. 



Find the resulting array after performing all the queries.

Input

The first line contains a single integer q (1 ≤ q ≤ 5 ⋅ 10^5) — the number of queries.

Next q lines contain queries (one per line). Each query is of one of two types: 

  * "1 x" (1 ≤ x ≤ 5 ⋅ 10^5); 
  * "2 x y" (1 ≤ x, y ≤ 5 ⋅ 10^5). 



It's guaranteed that there is at least one query of the first type.

Output

In a single line, print k integers — the resulting array after performing all the queries, where k is the number of queries of the first type.

Examples

Input


7
1 3
1 1
2 1 2
1 2
1 1
1 2
2 1 3


Output


3 2 2 3 2 

Input


4
1 1
1 2
1 1
2 2 2


Output


1 2 1 

Input


8
2 1 4
1 1
1 4
1 2
2 2 4
2 4 3
1 2
2 2 7


Output


1 3 3 7 

Note

In the first example, the array changes as follows:

[] → [3] → [3, 1] → [3, 2] → [3, 2, 2] → [3, 2, 2, 1] → [3, 2, 2, 1, 2] → [3, 2, 2, 3, 2].

In the second example, the array changes as follows:

[] → [1] → [1, 2] → [1, 2, 1] → [1, 2, 1].

In the third example, the array changes as follows:

[] → [] → [1] → [1, 4] → [1, 4, 2] → [1, 4, 4] → [1, 3, 3] → [1, 3, 3, 2] → [1, 3, 3, 7].

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long inv[601010];
long long p[601010];
long long num[601010];
long long arr[601010];
long long find(long long x) {
  if (p[x] == x) return x;
  return p[x] = find(p[x]);
}
long long uni(long long a, long long b) {
  a = find(a);
  b = find(b);
  if (a == b) return a;
  if (num[a] > num[b]) swap(a, b);
  num[b] = num[a] + num[b];
  p[a] = b;
  return b;
}
void solve() {
  long long Q;
  cin >> Q;
  long long i;
  long long cnt = 0;
  long long t, a, b;
  for (i = 1; i <= Q; i++) {
    cin >> t >> a;
    if (t == 2) cin >> b;
    if (t == 1) {
      cnt++;
      p[cnt] = cnt;
      num[cnt] = 1;
      if (inv[a]) {
        p[cnt] = inv[a];
        num[inv[a]]++;
      } else {
        arr[cnt] = a;
        inv[a] = cnt;
      }
    } else {
      if (a == b) continue;
      if (inv[a] == 0) continue;
      if (inv[b]) {
        long long x = inv[a];
        long long y = inv[b];
        long long u = uni(x, y);
        inv[a] = 0;
        inv[b] = u;
        arr[u] = b;
      } else {
        long long x = inv[a];
        arr[x] = b;
        inv[a] = 0;
        inv[b] = x;
      }
    }
  }
  for (i = 1; i <= cnt; i++) {
    long long x = find(i);
    cout << arr[x] << ' ';
  }
  cout << '\n';
}
void init() {}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long long T;
  T = 1;
  while (T--) {
    init();
    solve();
  }
}

```