#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
// defines
#define KhaledAshraf ios_base::sync_with_stdio(0);cin.tie(0);
#define modulo 1000000007
#define pi 3.1415926535897932384
typedef long long int lln;
//to be able to use to_string patch::to_string("char or string")
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
using namespace std;
/*******************************************/
/*
ya mas2la zebala accept b2a
O_O
$$$$$$$$$$$$$$$
$ $ $$$$$$$$$$$$$$$$$$$$$ $ $
$ $ $ $$$$$$$$$$$$$$$$$$$$$$$$ $ $ $
$ $ $ $ $$$$$$ $$$$$$ $$$$$$ $ $ $ $
$$$$$ $$$$$$ $$$$ $$$$$$$ $$$$$
$$$$$$$$ $$$$$$$ $$$$ $$$$$$$$ $$$$$$$$
$$$ $$$$$$$$$ $$$$$$ $$$$$$$$$$ $$$
$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ $
$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$
$$$ $$$$$$$$$$$$$$$$$$$$$$$$ $$$
$$$ $$$$$$$$$$$$$$$$ $$
$$ $$$$$$$$$$ $$
$$$ $
$$ $$$$$$$$$$$ $
$$$ $$$$$$$$$$$ $
$$$ $$$$$$$$$$
$$$$$ $$$$$$$$$
$$$$$$$
$$$$
Khaled Ashraf
*/
bool check[1000000];
vector <lln> primes;
void gen_primes(lln N){
for(lln i=2;i<=N;i++){
if(!check[i]){
primes.push_back(i);
for(lln j=i*i;j<=N;j+=i){
check[j]=true;
}
}
}
}
lln lcm (lln X , lln Y){
return ( (X*Y)/__gcd(X,Y) );
}
long long FastPower(long long B , long long P)
{
if(P==1){return B;}
else if(P%2)return B*FastPower(B*B,P/2);
else return FastPower(B*B,P/2);
}
lln GCD(lln X,lln Y){
if(X>Y){swap(X,Y);}
if(Y%X==0){return X;}
GCD(Y,Y%X);
}
bool proj(string S){
for(int i=0;i<S.size();i++){
if(S[i]>='a' && S[i]<='z'){
return false;
}
}
return true;
}
bool cmp(pair <int,string> A , pair<int,string> B){
if(A.first>B.first){
return 1;
}
else if(A.first<=B.first){
return 0;
}
}
int main()
{
KhaledAshraf;
bool flag=false;
string S;
while(getline(cin,S) && S[0]!='0'){
map <string,string>StudentsProject;
map <string,string>::iterator SPit;
map <string,int>cnt;
map <string,int>::iterator CNit;
string LastP="";
while(S[0]!='1'){
if(proj(S)==true){
LastP=S;
cnt[S]=0;
}
else{
if(StudentsProject[S]==LastP || StudentsProject[S]==""){
StudentsProject[S]=LastP;
}
else{
StudentsProject[S]=".";
}
}
getline(cin,S);
}
for(SPit=StudentsProject.begin() ; SPit!=StudentsProject.end() ;SPit++){
if(SPit->second !="."){
cnt[SPit->second]++;
}
}
vector <pair <int,string> >V;
for(CNit=cnt.begin() ; CNit!=cnt.end() ; CNit++){
V.push_back({(CNit->second),(CNit->first)});
}
sort(V.begin(),V.end(),cmp);
for(int i=0;i<V.size();i++){
cout<<V[i].second<<" "<<V[i].first<<endl;
}
}
return 0;
}