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 E{
  	static FastReader sc=null;
  	static int nax=(int)5e5+5;
  	
  	public static void main(String[] args) {
  		sc=new FastReader();
  		int q=sc.nextInt();
  		int ans[]=new int[nax],comp[]=new int[nax],val[]=new int[nax];
  		Arrays.fill(comp, -1);
  		Arrays.fill(val, -1);
  		
  		int cur=0;
  		DU du=new DU(nax);
  		
  		while(q-->0) {
  			int type=sc.nextInt();
  			
  			if(type==1) {
  				int x=sc.nextInt();
  				if(comp[x]==-1) {
  					//add
  					comp[x]=cur;
  					val[cur]=x;
  				}
  				else {
  					//already exists
  					du.unify(cur, comp[x]);
  					int par=du.find(cur);
  					comp[x]=par;
  					val[par]=x;
  				}
  				cur++;
  			}
  			else {
  				int x=sc.nextInt(),y=sc.nextInt();
  				int xc=comp[x],yc=comp[y];
  				
  				if(xc==-1 || x==y)continue;
  				else if(yc==-1) {
  					//change the par val to Y
  					int par=du.find(comp[x]);
  					comp[y]=par;
  					comp[x]=-1;
  					val[par]=y;
  				}
  				else {
  					//unify and change the par val to Y
  					du.unify(comp[x],comp[y]);
  					int par=du.find(comp[y]);
  					val[par]=y;
  					comp[y]=par;
  					comp[x]=-1;
  				}
  			}
  		}
  		
  		
  		for(int i=0;i<cur;i++) {
  			int par=du.find(i);
  			ans[i]=val[par];
  		}
  		PrintWriter out=new PrintWriter(System.out);
  		
  		for(int i=0;i<cur;i++)out.print(ans[i]+" ");
  		out.println();
  		
  		out.close();
  		
  	}
  	static class DU{
  		int sz[];
  		int par[];
  		int comp;
  		int n;
  		DU(int n){
  			this.n=n;
  			sz=new int[n];
  			Arrays.fill(sz, 1);
  			par=new int[n];
  			for(int i=0;i<n;i++)par[i]=i;
  			comp=n;
  		}
  		
  		int find(int p) {
  			if(par[p]==p)return p;
  			
  			return par[p]=find(par[p]);
  		}
  		
  		void unify(int p,int q) {
  			int r1=find(p),r2=find(q);
  			if(r1==r2)return;
  			
  			if(sz[r1]<sz[r2]) {
  				int temp=r1;
  				r1=r2;
  				r2=temp;
  			}
  			
  			sz[r1]+=sz[r2];
  			par[r2]=r1;
  			comp--;
  		}
  		
  		boolean connected(int p,int q) {
  			return find(p)==find(q);
  		}
  	}
  	
  	static int[] ruffleSort(int a[]) {
  		ArrayList<Integer> al=new ArrayList<>();
  		for(int i:a)al.add(i);
  		Collections.sort(al);
  		for(int i=0;i<a.length;i++)a[i]=al.get(i);
  		return a;
  	}
  	
  	static void print(int a[]) {
  		for(int e:a) {
  			System.out.print(e+" ");
  		}
  		System.out.println();
  	}
  	
  	static class FastReader{
  		
  		StringTokenizer st=new StringTokenizer("");
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		
  		String next() {
  			while(!st.hasMoreTokens()) 
  				try {
  					st=new StringTokenizer(br.readLine());
  				}
  			   catch(IOException e){
  				   e.printStackTrace();
  			   }
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  		
  		int[] readArray(int n) {
  			int a[]=new int[n];
  			for(int i=0;i<n;i++)a[i]=sc.nextInt();
  			return a;
  		}
  	}
  	
  	
  }
  