# This is a sample Python script. # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. def matches(lst, mask): mask = mask.replace("*", "?" * (10 - len(mask))) count = 0 for word in lst: for c1, c2 in zip(mask, word): if c1 == "?": continue elif c1 != c2: break else: count += 1 return count def earthquake(old, new): for n in new: print(matches(old, n)) # Press the green button in the gutter to run the script. if __name__ == '__main__': # earthquake(["728147956", "606327482"], ["72814?956", "622629145"]) # earthquake(["606200400", "606200500", "606300500", "706200400"], ["?06200400", "6*00", "606?00?00"]) old_count = int(input()) old = [] for i in range(old_count): old.append(input()) new_count = int(input()) new = [] for i in range(new_count): new.append(input()) earthquake(old, new) # See PyCharm help at https://www.jetbrains.com/help/pycharm/