import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._

  val Array(n, f) = readLine.trim.split(' ').map(_.toInt)
  val map = mutable.Map[(String, String), Int]().withDefaultValue(0)
  for (_ ← 0 until n){
    val items = readLine.trim.split(' ').tail
    items.combinations(2).foreach{
      case Array(a, b) ⇒ if (a < b) map((a, b)) += 1 else map((b, a)) += 1
    }
  }
  val tuples: Seq[((String, String), Int)] = map.toSeq.filter { case (_, c) ⇒ c >= f }

  println(tuples.length)
  if (tuples.nonEmpty) println(
    tuples.map{case (k, _) ⇒ k}.sortWith{case ((a, b), (c, d)) ⇒ if (a == c) b > d else a > d}.map{case (a, b) ⇒ s"$a $b"}.mkString("\n")
  )

}
