struct animal{
int number;
int order;
animal(int n,int o):number(n),order(o){}
};
int main(){
int n,event,id;
int order=0;
queue<animal>dog;
queue<animal>cat;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&event,&id);
if(event==1&&id>0)dog.push(animal(id,order++));
else if(event==1&&id<0)cat.push(animal(id,order++));
else if(event==2&&id==0){//第一种方式领养
if(!dog.empty()&&!cat.empty()){//都非空
if(dog.front().order<cat.front().order){
printf("%d ",dog.front().number);
dog.pop();
}
else{
printf("%d ",cat.front().number);
cat.pop();
}
}else if(!dog.empty()&&cat.empty()){//狗非空
printf("%d ",dog.front().number);
dog.pop();
}else if(!cat.empty()&&dog.empty()){//猫非空
printf("%d ",cat.front().number);
cat.pop();
}
}
else if(event==2&&id==1){//第二种方式领养,收养狗
printf("%d ",dog.front().number);
dog.pop();
}
else if(event==2&&id==-1){//第二种方式领养,收养猫
printf("%d ",cat.front().number);
cat.pop();
}
}
return 0;
}