#!/usr/bin/env python3
n, m = map(int, input().split())
words = [input() for _ in range(n)]
for _ in range(m):
    number = input()
    corresponding = []
    for word in words:
        digits = ""
        for c in word:
            if c == "a" or c == "b" or c == "c": digits += "2"
            if c == "d" or c == "e" or c == "f": digits += "3"
            if c == "g" or c == "h" or c == "i": digits += "4"
            if c == "j" or c == "k" or c == "l": digits += "5"
            if c == "m" or c == "n" or c == "o": digits += "6"
            if c == "p" or c == "q" or c == "r" or c == "s": digits += "7"
            if c == "t" or c == "u" or c == "v": digits += "8"
            if c == "w" or c == "x" or c == "y" or c == "z": digits += "9"
        if digits == number:
            corresponding.append(word)
    print(len(corresponding), *sorted(corresponding))
