#include<iostream>
using namespace std;
const int N=1e6+10;
int list[N];
int n,op,x,y,top;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&op);
if(op==1)scanf("%d%d",&x,&y),list[x]=y;
if(op==2) scanf("%d",&x),printf("%d\n",list[x]);
if(op==3) scanf("%d",&x),list[x]=list[list[x]];
}
return 0;
}