#include<bits/stdc++.h>
using namespace std;
struct Node{
int score;
string id;
int lrank;
int trank;
int flag;
};
bool cmp(Node a,Node b){
if(a.score!=b.score) return a.score>b.score;
else return a.id<b.id;
}
int main()
{
//freopen("in.txt","r",stdin);
int n;cin>>n;
vector<Node> temp;
for(int i=1;i<=n;i++){
int t;cin>>t;
vector<Node> ppp;ppp.resize(t);
for(int j=0;j<t;j++){
cin>>ppp[j].id>>ppp[j].score;
ppp[j].flag=i;
}
sort(ppp.begin(),ppp.end(),cmp);
ppp[0].lrank=1;
temp.push_back(ppp[0]);
for(int j=1;j<ppp.size();j++){
if(ppp[j].score==ppp[j-1].score){
ppp[j].lrank=ppp[j-1].lrank;
}else{
ppp[j].lrank=j+1;
}
temp.push_back(ppp[j]);
}
}
cout<<temp.size()<<endl;
sort(temp.begin(),temp.end(),cmp);
temp[0].trank=1;
cout<<temp[0].id<<' '<<temp[0].trank<<' '<<temp[0].flag<<' '<<temp[0].lrank<<endl;
for(int i=1;i<temp.size();i++){
if(temp[i].score==temp[i-1].score){
temp[i].trank=temp[i-1].trank;
}else{
temp[i].trank=i+1;
}
cout<<temp[i].id<<' '<<temp[i].trank<<' '<<temp[i].flag<<' '<<temp[i].lrank<<endl;
}
return 0;
}