#include <stdio.h>
#include<iostream>
#include <string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
//PAT A1025 PAT Ranking
struct student{
char id[15];
int score;
int l_n;
int l_r;
}stu[3000];
bool cmp(student a,student b){
if(a.score!=b.score)return a.score>b.score;
else return strcmp(a.id,b.id)<0;//按照准考证号从小到大进行排序
}
int main(){
int n,k,num=0;//考生总数
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&k);
for(int j=0;j<k;i++){
scanf("%d%d",&stu[num].id,&stu[num].score);
stu[num].l_n=i;
num++;
}
sort(stu+num-k,stu+num,cmp);
stu[num-k].l_r=1;
for(int j=num-k+1;j<num;j++)
{
if(stu[j].score==stu[j-1].score){
stu[j].l_r=stu[j-1].l_r;
}else{
stu[j].l_r=j+1-num+k;
}
}
}
printf("%d",num);
sort(stu,stu+num,cmp);
int r=1;
for(int i=0;i<num;i++){
if(i>0&&stu[i].score!=stu[i-1].score){
r+=1;
}
printf("%s ",stu[i].id);
printf("%d %d %d\n",r,stu[i].l_n,stu[i].l_r);
}
return 0;
}