import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

int[int] cnt()
{
    int[int] c;
    for(string s; (s=readln().chomp()).length; )
    {
        immutable n = s.split(",")[0].to!int();
        if(n in c) ++c[n];
        else c[n]=1;
    }
    return c;
}

void main()
{
    auto a=cnt(), b=cnt();
    foreach(n;b.keys.sort())
        if(n in a)
            writeln(n," ",a[n]+b[n]);
}