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

lastmonth=set_data
thismonth=set_data

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

thismonth.each do |i|
    if(k[i]==nil)
         k[i]=0
        else
        k[i]+=1
    end
end

i=0
k.each do |num|
    puts "#{i} #{num+1}" if(num!=nil)&&(num>=2)
    i+=1
end