//sort
// 1025. PAT Ranking.cpp: 主項目文件。
#include "stdafx.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=30003;
struct Info{
char id[14];
int score;
int belongs,vRank;
int rank;
Info operator=(const Info &info){
strcpy(id,info.id);
score=info.score;
belongs=info.belongs;
vRank=info.vRank;
rank=info.rank;
return *this;
}
};
Info totalInfo[N];
void giveRank(Info *info,int length,int version){
if(version==0)
info[0].vRank=1;
else
info[0].rank=1;
for(int i=1;i<length;i++){
if(version==0){
if(info[i].score==info[i-1].score)
info[i].vRank=info[i-1].vRank;
else
info[i].vRank=i+1;
}
else{
if(info[i].score==info[i-1].score)
info[i].rank=info[i-1].rank;
else
info[i].rank=i+1;
}
}
}
bool cmp(Info m1,Info m2){
if(m1.score!=m2.score)
return m1.score>m2.score;
else
return strcmp(m1.id,m2.id)<0;
}
int main()
{
int caseCnt,totalCnt=0;
scanf("%d",&caseCnt);
for(int i=1;i<=caseCnt;i++){
int m;
scanf("%d",&m);
Info tInfo[303];
for(int j=0;j<m;j++){
scanf("%s%d",tInfo[j].id,&tInfo[j].score);
tInfo[j].belongs=i;
}
sort(tInfo,tInfo+m,cmp);
giveRank(tInfo,m,0);
for(int j=0;j<m;j++)
totalInfo[totalCnt++]=tInfo[j];
}
sort(totalInfo,totalInfo+totalCnt,cmp);
giveRank(totalInfo,totalCnt,1);
printf("%d\n",totalCnt);
for(int i=0;i<totalCnt;i++)
printf("%s %d %d %d\n",totalInfo[i].id,totalInfo[i].rank,totalInfo[i].belongs,totalInfo[i].vRank);
return 0;
}