letters = input() n = int(input()) def check_word(word: str, letters: str) -> bool: for letter in word: if letter not in letters: return False return True for _ in range(n): word = input() if 4 > len(word): continue if letters[0] not in word: continue if check_word(word, letters): print(word)