#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
struct node{
string first;
string second;
int count;
};
bool cmp(node a, node b)
{
return a.count>b.count;
}
int main()
{
freopen("in.txt","r",stdin);
string first;
string second;
vector<node> data;
while(cin>>first>>second)
{
node node1;
node1.first = first;
node1.second = second;
node1.count = 0;
data.push_back(node1);
}
map<string, int> mymap;
//第一遍遍历 统计频率
for(int i=0; i<data.size(); i++)
mymap[data[i].first]++;
for(int i=0; i<data.size(); i++)
data[i].count = mymap[data[i].first];
sort(data.begin(), data.end(), cmp);
for(int i=0; i<data.size(); i++)
cout<<data[i].first<<" "<<data[i].second<<endl;
} 不知道能过多少。。。。