def set_data1
    num=[]
    while gets
        return num if($_=="\n")
        s=$_.chomp.split(",").map(&:to_i)
        num<<s[0]
    end
end

def set_data2
    num=[]
    while gets
        s=$_.chomp.split(",").map(&:to_i)
        num<<s[0]
    end
end

lastmonth=[]
thismonth=[]
k=[]
t=[]

lastmonth=set_data1
thismonth=set_data2

lastmonth.each do |i|
    if(k[i]==nil)&&(i!=nil)
        k[i]=1
        else
        k[i]+=1
    end
end

thismonth.each do |i|
    if(t[i]==nil)&&(i!=nil)
         t[i]=1
        else
        t[i]+=1
    end
end
i=0
k.each do |num|
    puts "#{i} #{num+t[i]}" if(num!=nil)&&(t[i]!=nil)
    i+=1
end