#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<assert.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
/* size denotes the number of books in the pile */
/* Under the k-th book in the pile (inclusive), the up[k]-th book has minimum amount of unsolved problems */
char name[1000000][16];
int remain[1000000], up[1000000];
int main(){
int N;
int i, j, k, len, size;
assert( scanf("%d",&N)==1 );
assert( 1<=N && N<=1000000 );
size = 0;
while(N--){
assert( scanf("%d",&k)==1 );
if(k==-1){
assert( size > 0 );
printf("%d %s\n",size-1 - up[size-1], name[up[size-1]]);
size = up[size-1];
} else {
assert(scanf("%s",name[size])==1);
len = strlen(name[size]);
assert( 1<=len && len<=15 );
rep(i,len) assert( 'a'<=name[size][i]&&name[size][i]<='z' );
remain[size] = k;
if(k==0) continue;
if(remain[size] <= remain[up[size-1]]) up[size] = size;
else up[size] = up[size-1];
size++;
}
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPG1hdGguaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPGFzc2VydC5oPgojZGVmaW5lIFJFUChpLGEsYikgZm9yKGk9YTtpPGI7aSsrKQojZGVmaW5lIHJlcChpLG4pIFJFUChpLDAsbikKCi8qIHNpemUgZGVub3RlcyB0aGUgbnVtYmVyIG9mIGJvb2tzIGluIHRoZSBwaWxlICovCi8qIFVuZGVyIHRoZSBrLXRoIGJvb2sgaW4gdGhlIHBpbGUgKGluY2x1c2l2ZSksIHRoZSB1cFtrXS10aCBib29rIGhhcyBtaW5pbXVtIGFtb3VudCBvZiB1bnNvbHZlZCBwcm9ibGVtcyAqLwpjaGFyIG5hbWVbMTAwMDAwMF1bMTZdOwppbnQgcmVtYWluWzEwMDAwMDBdLCB1cFsxMDAwMDAwXTsKCmludCBtYWluKCl7CiAgaW50IE47CiAgCiAgaW50IGksIGosIGssIGxlbiwgc2l6ZTsKCiAgYXNzZXJ0KCBzY2FuZigiJWQiLCZOKT09MSApOwogIGFzc2VydCggMTw9TiAmJiBOPD0xMDAwMDAwICk7CgogIHNpemUgPSAwOwogIHdoaWxlKE4tLSl7CiAgICBhc3NlcnQoIHNjYW5mKCIlZCIsJmspPT0xICk7CiAgICBpZihrPT0tMSl7CiAgICAgIGFzc2VydCggc2l6ZSA+IDAgKTsKICAgICAgcHJpbnRmKCIlZCAlc1xuIixzaXplLTEgLSB1cFtzaXplLTFdLCBuYW1lW3VwW3NpemUtMV1dKTsKICAgICAgc2l6ZSA9IHVwW3NpemUtMV07CiAgICB9IGVsc2UgewogICAgICBhc3NlcnQoc2NhbmYoIiVzIixuYW1lW3NpemVdKT09MSk7CiAgICAgIGxlbiA9IHN0cmxlbihuYW1lW3NpemVdKTsKICAgICAgYXNzZXJ0KCAxPD1sZW4gJiYgbGVuPD0xNSApOwogICAgICByZXAoaSxsZW4pIGFzc2VydCggJ2EnPD1uYW1lW3NpemVdW2ldJiZuYW1lW3NpemVdW2ldPD0neicgKTsKICAgICAgcmVtYWluW3NpemVdID0gazsKCiAgICAgIGlmKGs9PTApIGNvbnRpbnVlOwogICAgICAKICAgICAgaWYocmVtYWluW3NpemVdIDw9IHJlbWFpblt1cFtzaXplLTFdXSkgdXBbc2l6ZV0gPSBzaXplOwogICAgICBlbHNlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1cFtzaXplXSA9IHVwW3NpemUtMV07CiAgICAgIHNpemUrKzsKICAgIH0KICB9CgogIHJldHVybiAwOwp9