
object Main extends App {
  import scala.io.StdIn._
  implicit val timeOrdering = TimeOrdering
  val firstLine = readLine.trim.split(' ').map(_.toInt)
  val secondLine = readLine.trim.split(' ').map(_.toInt)
  val times = (0 until firstLine.head).map(i ⇒ Time(firstLine(i * 2 + 1), firstLine(i * 2 + 2))) ++ (0 until secondLine.head).map(i ⇒ Time(secondLine(i * 2 + 1), secondLine(i * 2 + 2)))
  println(times.distinct.sorted.mkString(" "))

  object TimeOrdering extends Ordering[Time] {
    override def compare(x: Time, y: Time): Int = if (x.hour == y.hour) x.minute.compare(y.minute) else x.hour.compare(y.hour)
  }
}
case class Time(hour: Int, minute: Int) {
  override def toString: String = f"$hour:$minute%02d"
}
