#include <bits/stdc++.h>
using namespace std;
unordered_map<int,vector<int>> Map;
int SetAllValue = 0,SetAllTime = -1,cnt = 0;
void put(int k,int v){
if(Map.find(k) != Map.end()){
Map[k][0] = v;
Map[k][1] = cnt++;
}else{
Map[k] = {v,cnt++};
}
}
void setAll(int v){
SetAllValue = v;
SetAllTime = cnt++;
}
int get(int k){
if(Map.find(k) == Map.end()){
return -1;
}
vector<int>& value = Map[k];
if(value[1] > SetAllTime){
return value[0];
}else{
return SetAllValue;
}
}
int main() {
int N,opt,x,y;
Map.clear();
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
while(cin >> N){
for(int i = 0; i < N; i++){
cin >> opt;
if(opt == 1){
cin >> x >> y;
put(x,y);
}else if(opt == 2){
cin >> x;
cout << get(x) << endl;
}else{
cin >> x;
setAll(x);
}
}
}
return 0;
}