#include<iostream>
using namespace std;
typedef struct Node
{
int val;
struct Node* next;
}List;
// 创建头节点
List* head = new List;
// 将元素 y 插到x 后面
void insert(int x, int y)
{
List* p = head->next;
while (p != NULL)
{
if (p->val == x)
{
List* p1 = new List;
p1->val = y;
p1->next = p->next;
p->next = p1;
}
p = p->next;
}
}
// 询问x后的元素是什么 , 若x为最后一个元素 ,则返回 0
int ask(int x)
{
List* p = head->next;
while (1)
{
if (p->val == x)
{
if (p->next == NULL)
return 0;
else
{
p = p->next;
return p->val;
}
}
p = p->next;
}
}
//从表中删除x后面的那个元素
void remove(int x)
{
List* p = head->next;
while (p != NULL )
{
if (p->val == x)
{
p->next = p->next->next;
}
p = p->next;
}
}
int main()
{
List* pre = head;
List* p = new List;
p->val = 1;
pre->next = p;
pre = p;
p->next = NULL;
int Q;
cin >> Q;
while (Q--)
{
int x, y, t;
cin >> t;
if (t == 1)
{
cin >> x >> y;
insert(x, y);
}
else if (t == 2)
{
cin >> x;
cout << ask(x) << endl;
}
else
{
cin >> x;
remove(x);
}
}
}