/* Very straight forward just do it problem. */ fun main() { val (n, m) = readln().split(" ").map(String::toInt) val input = System.`in`.bufferedReader().readLines() val words = input.take(n).map { it to wordToDigit(it) }.groupBy({ it.second }) { it.first }.mapValues {it.value.reversed() } input.drop(n).forEach { number -> val result = words[number] if (result.isNullOrEmpty()) { println("0") } else { println("${result.size} ${result.joinToString(" ")}") } } } val lookup = mapOf( 'a' to 2, 'b' to 2, 'c' to 2, 'd' to 3, 'e' to 3, 'f' to 3, 'g' to 4, 'h' to 4, 'i' to 4, 'j' to 5, 'k' to 5, 'l' to 5, 'm' to 6, 'n' to 6, 'o' to 6, 'p' to 7, 'q' to 7, 'r' to 7, 's' to 7, 't' to 8, 'u' to 8, 'v' to 8, 'w' to 9, 'x' to 9, 'y' to 9, 'z' to 9 ) fun wordToDigit(word: String) = word.map { lookup[it]!! }.joinToString(separator = "")