#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct student{
char id[14
int score;
int local_rank;
int group_num;
int rank;
}student[300000];
bool cmp(struct student s1, struct student s2){
if(s1.score != s2.score)
return s1.score > s2.score;
else
return strcmp(s1.id, s2.id) < 0;
}
int main(){
int N, K, i, j, index = 0, _rank;
scanf("%d", &N);
for(i = 0; i < N; i++){
scanf("%d", &K);
for(j = 0; j < K; j++){
scanf("%s %d", student[index].id, &student[index].score);
student[index].group_num = i + 1;
index++;
}
sort(student + index - K, student + index, cmp);
_rank = 1;
for(j = index - K; j < index; j++){
if(j > index - K){
if(student[j].score == student[j - 1].score){
student[j].local_rank = student[j - 1].local_rank;
_rank++;
continue;
}
}
student[j].local_rank = _rank;
_rank++;
}
}
printf("%d\n", index);
sort(student, student + index, cmp);
_rank = 1;
for(i = 0; i < index; i++){
if(i != 0){
if(student[i].score == student[i - 1].score){
student[i].rank = student[i - 1].rank;
printf("%s %d %d %d\n", student[i].id, student[i].rank, student[i].group_num, student[i].local_rank);
_rank++;
continue;
}
}
student[i].rank = _rank;
printf("%s %d %d %d\n", student[i].id, student[i].rank, student[i].group_num, student[i].local_rank);
_rank++;
}
return 0;
}