import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    int[] ss,ss1;
    while(true){
	string s = readln();
	if(s == "\n") break;
	if(stdin.eof()) break;
	auto s1 = split(s,',');
	ss ~= to!int(s1[0]);
	ss1 ~= to!int(s1[0]);
    }
    int[] list;
    while(true){
	string s = readln();
	if(s == "\n") break;
	if(stdin.eof()) break;
	auto s1 = split(s,',');
	ss1 ~= to!int(s1[0]);
	for(int i=0;i<ss.length;i++){
	    if(ss[i] == to!int(s1[0])){
		bool flg = true;
		foreach(j;list) if(j == to!int(s1[0])) flg = false;
		if(flg) 
		    list ~= to!int(s1[0]);
	    }
	}
    }

    sort(list);
    foreach(i;list){
	int count = 0;
	foreach(j;ss1){
	    if(i == j) count++;
	}
	writef("%d %d\n",i,count);
    }
}