#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<climits>
#include<vector>
#include<stack>
#include<cmath>
#include <iostream>
#include <stack>
#include <string>
#include <utility>
using namespace std;

int main()
{
    int t;
    long n;
    long cnt=0;
    bool notfound;
    int i=0;
    string book;
    stack< pair<int,string> > mystack;
    //cin>>t;
    t=1000000;
    long mintillpos[1000001]={100001},min=100001;
    while(t--)
    {
        
        //cin>>n;
        n=rand()%100000+1;
        if(t%100==0)
        n=-1;
        if(n>0)
        {
            //cin>>book;
            book="Hello";
            
            mystack.push(make_pair(n,book));
            if(min>n)
            {
                min=n;
            }
            mintillpos[i]=min;
            i++;
            
        }
        else
        {
            cnt=0;
            while((mystack.top().first)!=min)
            {
                    mystack.pop();
                    cnt++;
                    i--;
            }
            cout <<mystack.top().first<<" "<<mystack.top().second<<endl;
            mystack.pop();
            i--;
            if(i>0)
                min=mintillpos[i-1];
            else
            {
                memset(mintillpos,100001,sizeof(mintillpos));
                min=100001;
            }
            cout<<1000000-t;
            
        }

    }
    return 0;
}
