// editor1
#include<stdlib.h>
#include<stdio.h>
struct Node 
{
    int id,dur;
    struct Node *prev;
    struct Node *next;
};
struct Node *create(int id,int dur )
{
    struct Node *newnode=(struct Node*)malloc(sizeof(struct Node));
    newnode->id=id;
    newnode->dur=dur;
    newnode->next=NULL;
    newnode->prev=NULL;
    return newnode;
}
void insert(int id,int dur,struct Node **head)
{
    struct Node *newnode=create(id,dur);
    if(*head==NULL)
    {
        *head=newnode;
    }
    else
    {
        struct Node *temp=*head;
        while(temp->next!=NULL)
        {
            temp=temp->next;
        }
        temp->next=newnode;
        newnode->prev=temp;
    }
}
void del(struct Node *temp)
{
    while(temp->next->next!=NULL)
    {
        temp=temp->next;
    }
    struct Node *newn=temp->next;
    temp->next=NULL;
    printf("%d %d",newn->id,newn->dur);
    free(newn);
}
void print(struct Node *temp)
{
    while(temp!=NULL)
    {
        printf("%d %d",temp->id,temp->dur);
        temp=temp->prev;
    }    
}
int main()
{
    int n;
    scanf("%d",&n);
    struct Node *head;
    if(n<=1)
    {
        printf("Log is empty");
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        int id,dur;
        scanf("%d %d",&id,&dur);
        insert(id,dur,&head);
    }
    del(head);
    print(head);