// editor4
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int id;
    int ar;
    struct node *next;
}nd;
nd *front=NULL,*rear=NULL;
void enqueue(int v,int t){
    nd *newnode=(nd*)malloc(sizeof(nd));
    newnode->id=v;
    newnode->ar=t;
    newnode->next=NULL;
    if(front==NULL){
        front=rear=newnode;
    }
    else{
        rear->next= newnode;
        rear=newnode;
    }
    while(front!=NULL){
        
    }
}
void dequeue(){
    if(front==NULL){
        printf("queue is empty");
        return;
    }
    while(front!=NULL){
        printf("%d\n",front->id);
        front=front->next;
    }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
      int x,y;
      if(scanf("%d %d",&x,&y)!=2){
          printf("Invalid input");
          return 0;
      }
      if(x<=0 || y<0){
         printf("Invalid input");
        return 0;
      }
       enqueue(x,y);
    }
    dequeue();
   
    
}