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.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.Objects;
  import java.util.StringTokenizer;
  import java.io.Writer;
  import java.io.OutputStreamWriter;
  import java.io.BufferedReader;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   */
  public class Main {
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          OutputWriter out = new OutputWriter(outputStream);
          EReplaceTheNumbers solver = new EReplaceTheNumbers();
          solver.solve(1, in, out);
          out.close();
      }
  
      static class EReplaceTheNumbers {
          public void solve(int testNumber, InputReader in, OutputWriter out) {
              int q = in.nextInt();
              ArrayList<Pair> queries = new ArrayList<>();
  
              int last = -1;
              int[] color = new int[500005];
              for (int i = 1; i <= 500000; i++) color[i] = i;
              for (int i = 0; i < q; i++) {
                  int t = in.nextInt();
                  if (t == 1) {
                      int x = in.nextInt();
  //                uf.sz[x]++;
                      queries.add(new Pair(1, x, 0));
                  } else {
                      last = i;
                      int x = in.nextInt(), y = in.nextInt();
  //                uf.merge(y,x);
                      queries.add(new Pair(2, x, y));
                  }
              }
              ArrayList<Integer> ans = new ArrayList<>();
              for (int i = q - 1; i >= 0; i--) {
                  Pair p = queries.get(i);
                  if (p.a == 1) {
                      ans.add(color[p.b]);
                  } else {
  //                if(color[p.c]>0)
                      color[p.b] = color[p.c];
  //                out.println(i,uf.find(p.b));
                  }
              }
              for (int i = ans.size() - 1; i >= 0; i--) out.print(ans.get(i) + " ");
          }
  
          class Pair {
              int a;
              int b;
              int c;
  
              Pair(int a, int b, int c) {
                  this.a = a;
                  this.b = b;
                  this.c = c;
              }
  
              public int hashCode() {
                  return Objects.hash(a, b);
              }
  
              public boolean equals(Object obj) {
                  Pair that = (Pair) obj;
                  return a == that.a && b == that.b;
              }
  
              public String toString() {
                  return "[" + a + ", " + b + "]";
              }
  
          }
  
      }
  
      static class OutputWriter {
          private final PrintWriter writer;
  
          public OutputWriter(OutputStream outputStream) {
              writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
          }
  
          public OutputWriter(Writer writer) {
              this.writer = new PrintWriter(writer);
          }
  
          public void print(Object... objects) {
              for (int i = 0; i < objects.length; i++) {
                  if (i != 0) {
                      writer.print(' ');
                  }
                  writer.print(objects[i]);
              }
          }
  
          public void close() {
              writer.close();
          }
  
      }
  
      static class InputReader {
          BufferedReader reader;
          StringTokenizer tokenizer;
  
          public InputReader(InputStream stream) {
              reader = new BufferedReader(new InputStreamReader(stream), 32768);
              tokenizer = null;
          }
  
          public String next() {
              while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                  try {
                      tokenizer = new StringTokenizer(reader.readLine());
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              }
              return tokenizer.nextToken();
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
      }
  }
  
  