#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct company
{
	int num;
	int biz;
	int last;
	bool two;
	
	bool operator<(const company &c)
	{
		return this->num < c.num;
	}
} business[10000];

int main()
{
	int n, d;
	
	for (int i = 0; i < 10000; i++){
		business[i].num = i;
	}
	while (scanf("%d,%d", &n, &d) != EOF){
		
		business[n].biz++;
		if (business[n].last >= d){
			business[n].two = true;
		}
		else {
			business[n].last = d;
		}
	}
	for (int i = 0; i < 10000; i++){
		if (business[i].two){
			printf("%d %d\n", business[i].num, business[i].biz);
		}
	}
	
	return 0;
}