#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define _CRT_SECURE_NO_WARNINGS
#define endl '\n'
#define time clock_t tStart = clock();
#define show printf("Time taken: %.6fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define loop(a,b) for(int i=a;i<=b;++i)
#define count_1(n) __builtin_popcountll(n)
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define itoc(c) ((char)(((int)'0')+c))
#define V vector<int>
#define Vl vector<ll>
#define pll pair<ll,ll>
#define Vp vector<pair<int,int>>
#define all(v) v.begin(),v.end()
#define mid(s,e) (s+(e-s)/2)
#define tcase() ll t,n; cin>>t;n=t; while(t--)
#define eb emplace_back
#define ull unsigned long long
#define minimize INT_MAX
#define maximize INT_MIN
#define dsort(a) sort(a.begin(), a.end(), greater<int>())
#define fr(i,n) for(ll i=0; i<n; i++)
#define fr1(i,n) for(ll i=1; i<=n; i++)
#define vp(n) vector<pair<int,int>>v(n);
#define si set <int>
void fast(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//cout.setf(ios::fixed);
//cout.precision(20);
#ifndef _offline
// freopen("mex.in", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
}
bool compare(pair<string, int> p1 , pair<string, int> p2){
if (p1.second != p2.second){
return p1.second > p2.second;
}
return p1.first < p2.first;
}
void HaXn() {
int t; cin >> t;
map <string, double>mp;
while (t--){
int n; cin >>n;
double val = 1000.0;
map <string , int>mp2;
fr(i,n){
string str; cin >> str;
if (!mp2[str]) {
mp[str] += round(val);
val -= round((val * (10.0 / 100.0)));
}
mp2[str] ++;
}
}
vector<pair <string, double>>v(mp.size());
int index =0;
for (auto val : mp){
v[index].first = val.first;
v[index].second = val.second;
index ++;
}
sort(v.begin(),v.end(), compare);
cout << v[0].first << endl;
for (auto val: v){
cout << val.f << " "<< val.s << endl;
}
}
int main() {
fast();
HaXn();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGNtYXRoPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsICAgICAgICAgICAgICAgICAgICAgbG9uZyBsb25nCiNkZWZpbmUgX0NSVF9TRUNVUkVfTk9fV0FSTklOR1MKI2RlZmluZSBlbmRsICAgICAgICAgICAgICAgICAgICdcbicKI2RlZmluZSB0aW1lIGNsb2NrX3QgdFN0YXJ0ID0gY2xvY2soKTsKI2RlZmluZSBzaG93IHByaW50ZigiVGltZSB0YWtlbjogJS42ZnNcbiIsIChkb3VibGUpKGNsb2NrKCkgLSB0U3RhcnQpL0NMT0NLU19QRVJfU0VDKTsKI2RlZmluZSBsb29wKGEsYikgICAgICAgICAgICAgZm9yKGludCBpPWE7aTw9YjsrK2kpCiNkZWZpbmUgY291bnRfMShuKSAgICAgICAgICAgIF9fYnVpbHRpbl9wb3Bjb3VudGxsKG4pCiNkZWZpbmUgcGIgICAgICAgICAgICAgICAgICAgIHB1c2hfYmFjawojZGVmaW5lIGYgICAgICAgICAgICAgICAgICAgICBmaXJzdAojZGVmaW5lIHMgICAgICAgICAgICAgICAgICAgICBzZWNvbmQKI2RlZmluZSBNT0QgICAgICAgICAgICAgICAgICAgMTAwMDAwMDAwNwojZGVmaW5lIGl0b2MoYykgICAgICAgICAgICAgICAoKGNoYXIpKCgoaW50KScwJykrYykpCiNkZWZpbmUgViAgICAgICAgICAgICAgICAgICAgIHZlY3RvcjxpbnQ+CiNkZWZpbmUgVmwgICAgICAgICAgICAgICAgICAgICAgdmVjdG9yPGxsPgojZGVmaW5lIHBsbCAgICAgICAgICAgICAgICAgICBwYWlyPGxsLGxsPgojZGVmaW5lIFZwICAgICAgICAgICAgICAgICAgICB2ZWN0b3I8cGFpcjxpbnQsaW50Pj4KI2RlZmluZSBhbGwodikgICAgICAgICAgICAgICAgdi5iZWdpbigpLHYuZW5kKCkKI2RlZmluZSBtaWQocyxlKSAgICAgICAgICAgICAgKHMrKGUtcykvMikKI2RlZmluZSB0Y2FzZSgpICAgICAgICAgICAgICAgbGwgdCxuOyBjaW4+PnQ7bj10OyB3aGlsZSh0LS0pCiNkZWZpbmUgZWIgICAgICAgICAgICAgICAgICAgIGVtcGxhY2VfYmFjawojZGVmaW5lIHVsbCAgICAgICAgICAgICAgICAgICB1bnNpZ25lZCBsb25nIGxvbmcKI2RlZmluZSBtaW5pbWl6ZSAgICAgICAgICAgICAgSU5UX01BWAojZGVmaW5lIG1heGltaXplICAgICAgICAgICAgICBJTlRfTUlOCiNkZWZpbmUgZHNvcnQoYSkgICAgICAgICAgICAgIHNvcnQoYS5iZWdpbigpLCBhLmVuZCgpLCBncmVhdGVyPGludD4oKSkKI2RlZmluZSBmcihpLG4pICAgICAgICAgICAgICAgZm9yKGxsIGk9MDsgaTxuOyBpKyspCiNkZWZpbmUgZnIxKGksbikgICAgICAgICAgICAgIGZvcihsbCBpPTE7IGk8PW47IGkrKykKI2RlZmluZSB2cChuKSAgICAgICAgICAgICAgICB2ZWN0b3I8cGFpcjxpbnQsaW50Pj52KG4pOwojZGVmaW5lIHNpICAgICAgICAgICAgICAgICAgIHNldCA8aW50PgoKdm9pZCBmYXN0KCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNvdXQudGllKDApOwogICAgLy9jb3V0LnNldGYoaW9zOjpmaXhlZCk7CiAgICAvL2NvdXQucHJlY2lzaW9uKDIwKTsKICAgICNpZm5kZWYgX29mZmxpbmUKICAgIC8vIGZyZW9wZW4oIm1leC5pbiIsICJyIiwgc3RkaW4pOwogICAgLy9mcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgI2VuZGlmCn0KCmJvb2wgY29tcGFyZShwYWlyPHN0cmluZywgaW50PiBwMSAsIHBhaXI8c3RyaW5nLCBpbnQ+IHAyKXsKICAgIGlmIChwMS5zZWNvbmQgIT0gcDIuc2Vjb25kKXsKICAgICAgICByZXR1cm4gcDEuc2Vjb25kID4gcDIuc2Vjb25kOwogICAgfQogICAgcmV0dXJuIHAxLmZpcnN0IDwgcDIuZmlyc3Q7Cn0KCnZvaWQgSGFYbigpIHsKICAgIGludCB0OyBjaW4gPj4gdDsKICAgIG1hcCA8c3RyaW5nLCBkb3VibGU+bXA7CiAgICB3aGlsZSAodC0tKXsKICAgICAgICBpbnQgbjsgY2luID4+bjsKICAgICAgICBkb3VibGUgdmFsID0gMTAwMC4wOwogICAgICAgIG1hcCA8c3RyaW5nICwgaW50Pm1wMjsKICAgICAgICBmcihpLG4pewogICAgICAgICAgICBzdHJpbmcgc3RyOyBjaW4gPj4gc3RyOwogICAgICAgICAgICBpZiAoIW1wMltzdHJdKSB7CiAgICAgICAgICAgICAgICBtcFtzdHJdICs9IHJvdW5kKHZhbCk7CiAgICAgICAgICAgICAgICB2YWwgLT0gcm91bmQoKHZhbCAqICgxMC4wIC8gMTAwLjApKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbXAyW3N0cl0gKys7CiAgICAgICAgfQogICAgfQogICAgdmVjdG9yPHBhaXIgPHN0cmluZywgZG91YmxlPj52KG1wLnNpemUoKSk7CiAgICBpbnQgaW5kZXggPTA7CiAgICBmb3IgKGF1dG8gdmFsIDogbXApewogICAgICAgIHZbaW5kZXhdLmZpcnN0ID0gdmFsLmZpcnN0OwogICAgICAgIHZbaW5kZXhdLnNlY29uZCA9IHZhbC5zZWNvbmQ7CiAgICAgICAgaW5kZXggKys7CiAgICB9CiAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpLCBjb21wYXJlKTsKICAgIGNvdXQgPDwgdlswXS5maXJzdCA8PCBlbmRsOwogICAgZm9yIChhdXRvIHZhbDogdil7CiAgICAgICAgY291dCA8PCB2YWwuZiA8PCAiICI8PCB2YWwucyA8PCBlbmRsOwogICAgfQoKCn0KCgoKCgppbnQgbWFpbigpIHsKICAgIGZhc3QoKTsKICAgIEhhWG4oKTsKfQ==