description: 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].
solution: #include <bits/stdc++.h>
  using namespace std;
  const int MOD = 1e9 + 7;
  template <int mod>
  struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
      if ((x += p.x) >= mod) x -= mod;
      return *this;
    }
    ModInt &operator-=(const ModInt &p) {
      if ((x += mod - p.x) >= mod) x -= mod;
      return *this;
    }
    ModInt &operator*=(const ModInt &p) {
      x = (int)(1LL * x * p.x % mod);
      return *this;
    }
    ModInt &operator/=(const ModInt &p) {
      *this *= p.inverse();
      return *this;
    }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
      int a = x, b = mod, u = 1, v = 0, t;
      while (b > 0) {
        t = a / b;
        swap(a -= t * b, b);
        swap(u -= t * v, v);
      }
      return ModInt(u);
    }
    ModInt pow(int64_t n) const {
      ModInt ret(1), mul(x);
      while (n > 0) {
        if (n & 1) ret *= mul;
        mul *= mul;
        n >>= 1;
      }
      return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
    friend istream &operator>>(istream &is, ModInt &a) {
      int64_t t;
      is >> t;
      a = ModInt<mod>(t);
      return (is);
    }
    static int get_mod() { return mod; }
  };
  using mint = ModInt<MOD>;
  long long mod_pow(long long x, long long n) {
    if (n == 0) return 1;
    long long res = mod_pow(x * x % MOD, n / 2);
    if (n & 1) res = res * x % MOD;
    return res;
  }
  long long power(long long num, long long pw) {
    if (pw == 0) return 1;
    long long res = power(num * num, pw / 2);
    if (pw & 1) res *= pw;
    return res;
  }
  long long ln(long long num, long long base) {
    int steps = 0;
    while (num > 1) {
      num /= base;
      steps++;
    }
    return steps;
  }
  int S = 100001;
  vector<int> Seive(S);
  void seive() {
    fill(Seive.begin(), Seive.end(), 0);
    Seive[0] = 0;
    Seive[1] = 0;
    for (long long i = 2; i <= S; i++) {
      if (Seive[i]) continue;
      for (long long j = i * i; j <= S; j += i) Seive[j] = 1;
    }
  }
  long long gcd(long long int a, long long int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
  }
  long long lcm(int a, int b) { return (a / gcd(a, b)) * b; }
  bool sortbysec(const pair<long long, char> &a, const pair<long long, char> &b) {
    if (a.second == b.second) return a.first < b.first;
    return (a.second < b.second);
  }
  bool compare(const pair<string, int> &a, const pair<string, int> &b) {
    for (int i = 0; i < a.first.length(); i++) {
      if (i % 2 == 0) {
        if (a.first[i] < b.first[i]) return true;
        if (a.first[i] > b.first[i]) return false;
      } else {
        if (a.first[i] > b.first[i]) return true;
        if (a.first[i] < b.first[i]) return false;
      }
    }
  }
  int binarySearch(vector<pair<int, int>> a) {
    int r = a.size();
    int l = 1;
    int ans = r;
    while (l <= r) {
      int mid = (l + r) / 2;
      int rem = mid, curr = 0;
      for (int i = 0; i < a.size(); i++) {
        if (a[i].first >= rem - 1) {
          if (a[i].second >= curr) {
            curr++;
            rem--;
          }
        }
      }
      if (rem <= 0) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    return ans;
  }
  void toggle(bool &x) { x ^= 1; }
  void solve() {
    int q;
    cin >> q;
    map<int, list<int>> m;
    int i = 0;
    while (q--) {
      int num;
      cin >> num;
      if (num == 1) {
        int x;
        cin >> x;
        m[x].push_back(i);
        i++;
      } else {
        int x, y;
        cin >> x >> y;
        if (x == y) continue;
        if (m[x].size() > m[y].size()) m[x].swap(m[y]);
        for (auto &i : m[x]) {
          m[y].push_back(i);
        }
        m.erase(x);
      }
    }
    vector<int> v(i);
    for (auto x : m) {
      for (auto y : x.second) {
        v[y] = x.first;
      }
    }
    for (auto x : v) {
      cout << x << " ";
    }
    cout << "\n";
  }
  int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    for (int T = 1; T <= t; T++) {
      solve();
    }
  }
  