#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <iterator>
using namespace std;
class CA
{
public:
struct position
{
int lastrank;
int lastscore;
int ranks;
position(){lastscore=-1;ranks=1;lastrank=0;}
};
void run();
map<int,map<string,int> > m;
};
void CA::run()
{
int n,k,score,testees=0,lastscore=-1,lastrank,ranks=1;
vector<position> pranks;
string sid;
cin>>n;
int i;
pranks.push_back(position());
for(i=1;i<=n;i++)
{
pranks.push_back(position());
cin>>k;
while(k-->0)
{
testees++;
cin>>sid>>score;
m[score][sid]=i;
}
}
cout<<testees<<endl;
map<int,map<string,int > >::reverse_iterator im;
for(im=m.rbegin();im!=m.rend();im++)
{
map<string,int>::iterator im1;
for(im1=im->second.begin();im1!=im->second.end();im1++)
{
cout<<im1->first;
if(im->first==lastscore)
{
cout<<" "<<lastrank;
}
else
{
cout<<" "<<ranks;
lastrank=ranks;
lastscore=im->first;
}
ranks++;
cout<<" "<<im1->second;
if(im->first == pranks[im1->second].lastscore)
{
cout<<" "<<pranks[im1->second].lastrank;
}
else
{
cout<<" "<<pranks[im1->second].ranks;
pranks[im1->second].lastrank=pranks[im1->second].ranks;
pranks[im1->second].lastscore=im->first;
}
(pranks[im1->second].ranks)++;
cout<<endl;
}
}
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}