#include<iostream>
using namespace std;
struct Node {
int val;
Node* next;
};
Node* head=NULL;
void Print() {
Node* temp = head;
while (temp != NULL) {
cout << temp->val<<" ";
temp = temp->next;
}
cout << "\n";
}
void Insert(int x, int y) {
Node* temp = new Node;
temp->val = y;
Node* p = head;
while (p->val != x) {
p = p->next;
}
temp->next = p->next;
p->next = temp;
}
void Research(int x) {
Node* p=head;
while (p->val != x) {
p = p->next;
if (p->next == NULL) {
cout << 0<<endl;
return;
}
}
p = p->next;
cout << p->val << endl;
return;
}
void del(int x) {
Node* p = head;
while (p->val != x) {
p = p->next;
}
Node* p1=p->next;
Node* p2 = p->next;
p1=p1->next;
p->next = p1;
delete p2;
}
int main() {
Node* temp = new Node();
temp->val = 1;
temp->next = head;
head = temp;
int t;
cin >> t;
while (t--) {
int op,x,y;
cin >> op;
if (op == 1) {
cin >> x>>y;
Insert(x,y);
}
else if (op == 2) {
cin >> x;
Research(x);
}
else if (op == 3) {
cin >> x;
del(x);
}
}
return 0;
}