#include<iostream>
using namespace std;
const int N = 1E6;
int a[N+1];
int main()
{
int q, c, x, y, next;
cin >> q;
while(q--)
{
cin >> c;
if(c == 1)
{
cin >> x >> y;
next = a[x];
a[x] = y;
a[y] = next;
}
else if(c == 2)
{
cin >> x;
cout << a[x] << endl;
}
else
{
cin >> x;
next = a[x];
a[x] = a[next];
}
}
return 0;
}