#include<bits/stdc++.h>
using namespace std;
int a[1000010];
int main()
{
int q;
scanf("%d",&q);
int tot=1;
a[1]=1;
while(q--)
{
int n;
scanf("%d",&n);
if(n==1)
{
int x,y;
scanf("%d%d",&x,&y);
for(int i=1;i<=tot;i++)
{
if(a[i]==x)
{
tot++;
for(int j=i+2;j<=tot;j++)
{
a[j]=a[j-1];
}
a[i+1]=y;
}
}
}
if(n==2)
{
int x;
scanf("%d",&x);
for(int i=1;i<=tot;i++)
{
if(a[i]==x)
{
printf("%d\n",a[i+1]);
}
}
}
if(n==3)
{
int x;
scanf("%d",&x);
for(int i=1;i<=tot;i++)
{
if(a[i]==x)
{
a[i+1]=0;
for(int j=i+1;j<=tot;j++)
{
a[j]=a[j+1];
}
}
}
tot--;
}
}
return 0;
}
满江红