import numpy as np
from scipy.spatial.distance import minkowski

n, m = map(int, input().split())
a = np.array([list(map(int, input().split())) for i in range(n)])
for i in range(m):
    b = np.array(list(map(int,input())))
    c = np.array([minkowski(i, b , 1) for i in a], dtype=np.int64)
    ans = np.argmin(c) + 1
    print(ans)