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: import java.io.*;
  import java.util.*;
  
  public class Main {
      class JoinSet {
          int[] fa;
          JoinSet(int n){
              fa = new int[n];
              for(int i = 0;i < n;i++) fa[i] = i;
          }
          int find(int x){
              if(x != fa[x]) fa[x] = find(fa[x]);
              return fa[x];
          }
          void join(int x, int y){
              x = find(x);
              y = find(y);
              fa[x] = y;
          }
      }
      static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
      static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
      static int mod = (int)1e9+7;
      static boolean[] isprime=new boolean[1];
      static {
          for(int i=2;i<isprime.length;i++) isprime[i]=true;
          for(int i=2;i<isprime.length;i++) {
              if(isprime[i]) {
                  for(int k = 2; i*k<isprime.length; k++) {
                      isprime[i*k] = false;
                  }
              }
          }
      }
      public static long gcd(long a, long b){
          return b == 0 ? a : gcd(b,a%b);
      }
      public static long lcm(long a, long b){
          return a*b / gcd(a,b);
      }
      public static int get() throws Exception{
          String ss = bf.readLine();
          if (ss.contains(" ")) ss = ss.substring(0, ss.indexOf(" "));
          return Integer.parseInt(ss);
      }
      public static int[] getInt() throws Exception {
          String s[] = bf.readLine().split(" ");
          int[] a = new int[s.length];
          for(int i = 0;i < a.length;i++){
              a[i] = Integer.parseInt(s[i]);
          }
          return a;
      }
      public static long[] getLong() throws Exception {
          String s[] = bf.readLine().split(" ");
          long[] a = new long[s.length];
          for(int i = 0;i < a.length;i++){
              a[i] = Long.parseLong(s[i]);
          }
          return a;
      }
      public static void print(int[] a) throws Exception {
          for(int i : a){
              bw.write(i + " ");
          }
          println();
      }
      public static void print(long[] a) throws Exception {
          for(long i : a){
              bw.write(i + " ");
          }
          println();
      }
      public static void println() throws Exception{
          bw.write("\n");
      }
      public static long pow(long a, long b){
          long ans = 1;
          while(b > 0){
              if((b&1) == 1){
                  ans *= a;
              }
              a*=a;
              b>>=1;
          }
          return ans;
      }
      public static int powmod(long a, long b, int mod){
          long ans = 1;
          while(b > 0){
              if((b&1) == 1){
                  ans = ans * a % mod;
              }
              a = a * a % mod;
              b>>=1;
          }
          return (int)ans;
      }
      public static void sort(int[] a){
          int n = a.length;
          Integer[] b = new Integer[n];
          for(int i = 0;i < n;i++) b[i] = a[i];
          Arrays.sort(b);
          for(int i = 0;i < n;i++) a[i] = b[i];
      }
  
      public static void main(String[] args) throws Exception {
          int n = get();
          int b[] = new int[500005];
          for(int i = 0;i < b.length;i++) b[i] = i;
          List<Integer> list = new ArrayList<>();
          int[] op = new int[n], x = new int[n], y = new int[n];
          for(int i = 0;i < n;i++){
              int[] t = getInt();
              op[i] = t[0];
              x[i] = t[1];
              if(op[i] == 2) y[i] = t[2];
          }
          for(int i = n-1;i >= 0;i--){
              if(op[i] == 2) b[x[i]] = b[y[i]];
              else list.add(b[x[i]]);
          }
          for(int i = list.size()-1;i >= 0;i--){
              bw.write(list.get(i) + " ");
          }
          println();
          bw.flush();
      }
  }
  