from collections import deque

def get_moves(x,y):
# def get_moves(y,x):
    l = [[x+1,y], [x+1,y+1], [x,y+1], [x+1,y-1], [x,y-1], [x-1,y-1], [x-1,y], [x-1,y+1]]
    # print(l)
    l = list(filter(lambda x: ((-1< x[0] <max_x) and (-1< x[1] <max_y)), l))
    # l = [[x[1],x[0]] for x in l]
    # print(l)
    return l

def BFS(start):
    visited = [[False]*max_x for x in range(max_y)]
    cnt_matrix = [[0]*max_x for x in range(max_y)]
    bfs_queue = deque()
    bfs_queue.append(start)
    cnt = 0
    tmp = '>'
    while len(bfs_queue) != 0:
        x = bfs_queue.popleft()
        xi,xj = x[0],x[1]
        neigh = get_moves (xi,xj)
        cnt += 1
        # print('from {}'.format(x))
        for w in neigh:
            # print(tmp*cnt,end='')
            # print(w)
            wj,wi = w[0],w[1]
            # if not visited[wi][wj]:
            if not visited[wi][wj]:
                bfs_queue.append(w)
                visited[wi][wj] = True
                cnt_matrix[wi][wj] = 1 + cnt_matrix[xj][xi]
            if matrix[wi][wj] == 1:
                # for x in cnt_matrix[::-1]:
                #     print(x)
                return cnt_matrix[wi][wj]


guard_cnt, incident_cnt = map(int, input().split())
# print(guard_cnt)
# print(incident_cnt)

guard_coord = [list(map(int, input().split())) for x in range(guard_cnt)]
incident_coord = [list(map(int, input().split())) for x in range(incident_cnt)]
# print(guard_coord)
# print(incident_coord)
common = []
common.extend(guard_coord)
common.extend(incident_coord)
common_x = [x[0] for x in common]
common_y = [y[1] for y in common]
max_x = max(common_x) + 1
max_y = max(common_y) + 1

# print(max_x)
# print(max_y)

matrix = [[0]*max_x for x in range(max_y)]
# print(matrix)

for x in guard_coord:
    i,j = x[0],x[1]
    matrix[j][i] = 1

for x in incident_coord:
    i,j = x[0],x[1]
    # print(i,j)
    matrix[j][i] = 2

# matrix = matrix[::-1]
# for x in matrix[::-1]:
#     print(x)

# print(BFS(incident_coord[1]))
flag = True
for x in incident_coord:
    for w in guard_coord:
        if w == x:
            flag = False
            print(0)
            break

    if flag == True:
        print(BFS(x))
    flag = True
