def extract_arguments(fh):
    result = []
    while True:
        n, m = map(int, fh.readline().strip().split())
        if n == 0 and m == 0:
            break
        winning_numbers = []
        for _ in range(n):
            Ni, Mi = fh.readline().strip().split()
            Mi = int(Mi)
            winning_numbers.append((Ni, Mi))
        tickets = [fh.readline().strip() for _ in range(m)]
        result.append((winning_numbers, tickets))
    return result