import scala.io.StdIn.readLine
import scala.collection.mutable.HashMap

object Main extends App {
  val m = HashMap.empty[Int,Int]
  val m2 = HashMap.empty[Int,Int]
  Iterator.continually(readLine).takeWhile(_!="").foreach { s =>
    val n = s.split(",").map(_.toInt)
    if(m contains n(0)) m(n(0)) += 1 else m += (n(0) -> 1)
  }

  Iterator.continually(readLine).takeWhile(_!=null).foreach { s =>
    val n = s.split(",").map(_.toInt)
    if(m contains n(0)) {
      if(m2 contains n(0)) m2(n(0)) += 1 else m2 += (n(0) -> (m(n(0)) + 1))
    }
  }
  m2.toSeq.sorted.foreach { case (x,y) => println(x + " " + y) }
}