#include<iostream>
#include<map>
#define N 30
#define M 9999999
#define FOR(i,s,t) for(int i=(s);i<=(t);++i)
#include<string>
#include<string.h>
#include<algorithm>
#include<memory.h>
using namespace std;
int nn;
map<string,int,less<string> >h;
std::map<string,int>::iterator t;
int add_name(string &name)
{ if(h.find(name)==h.end())
{ nn++;
h.insert(pair<string,int> (name,nn));
return nn;
}
return h[name];
}
int main()
{ int n;
cin>>n;
nn=0;
for(int i=0;i!=n;i++)
{ string a,b;
int e;
cin>>a>>b;
int c=add_name(a);
int d=add_name(b);
}
for(t=h.begin();t!=h.end();++t)
cout<<t->first<<" "<<t->second<<endl;
system("pause");
//return 0;
}