#include<bits/stdc++.h>
typedef long long ll;
const int maxn = 1e4 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
using namespace std;
struct node {
    string x, m;
}f[maxn];
map<string, int>mp;
bool cmp(node a, node b) {
    return mp[a.x] > mp[b.x];
}
int main() {
    int i = 0;
    while (cin >> f[i].x >> f[i].m) {
        mp[f[i].x]++;
        i++;
    }
    stable_sort(f, f + i, cmp);
    for (int x = 0; x < i; x++) {
        cout << f[x].x << " " << f[x].m << endl;
    }
    return 0;
}