#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
struct dsu {
  int head[500005], size[500005], value[500005];
  dsu() {
    memset(head, -1, sizeof(head));
    for (int i = 0; i <= 500000; ++i) value[i] = i;
    for (int i = 0; i <= 500000; ++i) size[i] = 1;
  }
  int find_head(int node) {
    while (head[node] != -1) node = head[node];
    return node;
  }
  int merge(int a, int b) {
    int x = find_head(a), y = find_head(b);
    if (x != y) {
      if (size[x] > size[y])
        value[x] = value[y], size[x] += size[y], head[y] = x;
      else
        size[y] += size[x], head[x] = y;
    }
    return x != y;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  pair<bool, pair<int, int>> queries[q];
  int arr_size = 0;
  for (int i = 0; i < q; ++i) {
    int t, x, y;
    cin >> t;
    if (t == 1)
      cin >> x, queries[i] = make_pair(0, make_pair(x, 0)), ++arr_size;
    else
      cin >> x >> y, queries[i] = make_pair(1, make_pair(x, y));
  }
  reverse(queries, queries + q);
  int res[arr_size], idx = 0;
  int value[500005];
  memset(value, -1, sizeof(value));
  for (int i = 0; i < q; ++i) {
    if (queries[i].first) {
      value[queries[i].second.first] = value[queries[i].second.second];
      if (value[queries[i].second.first] == -1)
        value[queries[i].second.first] = queries[i].second.second;
    } else {
      res[idx++] = value[queries[i].second.first];
      if (res[idx - 1] == -1) res[idx - 1] = queries[i].second.first;
    }
  }
  reverse(res, res + arr_size);
  for (int i = 0; i < arr_size; ++i) cout << res[i] << " ";
  cout << "\n";
  return 0;
}

### Prompt

Your challenge is to write a cpp solution to 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("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
struct dsu {
  int head[500005], size[500005], value[500005];
  dsu() {
    memset(head, -1, sizeof(head));
    for (int i = 0; i <= 500000; ++i) value[i] = i;
    for (int i = 0; i <= 500000; ++i) size[i] = 1;
  }
  int find_head(int node) {
    while (head[node] != -1) node = head[node];
    return node;
  }
  int merge(int a, int b) {
    int x = find_head(a), y = find_head(b);
    if (x != y) {
      if (size[x] > size[y])
        value[x] = value[y], size[x] += size[y], head[y] = x;
      else
        size[y] += size[x], head[x] = y;
    }
    return x != y;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  pair<bool, pair<int, int>> queries[q];
  int arr_size = 0;
  for (int i = 0; i < q; ++i) {
    int t, x, y;
    cin >> t;
    if (t == 1)
      cin >> x, queries[i] = make_pair(0, make_pair(x, 0)), ++arr_size;
    else
      cin >> x >> y, queries[i] = make_pair(1, make_pair(x, y));
  }
  reverse(queries, queries + q);
  int res[arr_size], idx = 0;
  int value[500005];
  memset(value, -1, sizeof(value));
  for (int i = 0; i < q; ++i) {
    if (queries[i].first) {
      value[queries[i].second.first] = value[queries[i].second.second];
      if (value[queries[i].second.first] == -1)
        value[queries[i].second.first] = queries[i].second.second;
    } else {
      res[idx++] = value[queries[i].second.first];
      if (res[idx - 1] == -1) res[idx - 1] = queries[i].second.first;
    }
  }
  reverse(res, res + arr_size);
  for (int i = 0; i < arr_size; ++i) cout << res[i] << " ";
  cout << "\n";
  return 0;
}

```