/*************************
题意:
sort题。。。
/************************
求解要点和注意点:
重点应该就在于怎么求排名
排名里成绩相同,则排名相同。
这题用sort排序即可,不会超时
************************/

/***********************
笔记:

*********************/

#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define M 10010
#define INF 0x7fffffff

struct score{
string id;
int grade,gn;
int grank;
};

bool cmp(struct score a,struct score b){
if(a.grade > b.grade)
return true;
else if(a.grade == b.grade){
return a.id<b.id;
}
else return false;
}

int main(){
int n,k,i,j;
string id;
int grade;
vector<struct score> alls;
vector<struct score> vs;
struct score s;
scanf("%d",&n);
for(i = 1;i <= n; i++){
scanf("%d",&k);
vs.clear();
for(j=0;j<k;j++){
cin>>id>>grade;
s.id = id;
s.grade = grade;
s.gn = i;
vs.push_back(s);
}
sort(vs.begin(),vs.end(),cmp);
vs[0].grank = 1;
alls.push_back(vs[0]);
for(j = 1;j < vs.size(); j++){
if(vs[j].grade < vs[j-1].grade)
vs[j].grank = j + 1;
else vs[j].grank = vs[j-1].grank;
alls.push_back(vs[j]);
}
}

sort(alls.begin(),alls.end(),cmp);
int nowgrank=1;

cout<<alls.size()<<endl;
cout<<alls[0].id<<" "<<nowgrank<<" "<<alls[0].gn<<" "<<alls[0].grank<<endl;
for(i=1;i<alls.size();i++){
if(alls[i].grade < alls[i-1].grade)
nowgrank = i + 1;
cout<<alls[i].id<<" "<<nowgrank<<" "<<alls[i].gn<<" "<<alls[i].grank<<endl;
}


return 0;
}