#include<bits/stdc++.h>
using namespace std;
int main()
{
    int com[10000]={},cou[10000]={},day,be=0,n,co=0,kawa=0;
    char s;
    while(cin>>n>>s>>day){
        if(be>day)co=1;
        if(co==1){
            if(cou[n]==1)cou[n]=2;
            com[n]++;
            kawa++;
        }
        else{
            cou[n]=1;
            com[n]++;
            be=day;
        }
    }
    for(int i=0;i<kawa;i++){
        co=3000;day=0;
        for(int j=0;j<10000;j++){
            if(cou[j]==2&&com[j]<co){
                co=com[j];
                day=j;
            }
        }
        if(co==3000)break;
        cout<<day<<" "<<co<<endl;
        cou[day]=0;
    }
}