from collections import deque
from collections import defaultdict

def to_str(l):
    return ''.join([str(x) for x in l])

def get_moves(x,y):
    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]]
    l = list(filter(lambda x: ((-1< x[0] <max_x) and (-1< x[1] <max_y)), l))
    return l

def BFS(start):
    visited = defaultdict(lambda : False)
    cnt_matrix = defaultdict(lambda : 0)
    bfs_queue = deque()
    bfs_queue.append(start)
    cnt = 0
    while len(bfs_queue) != 0:
        x = bfs_queue.popleft()
        x_str = to_str(x)
        xi,xj = x[0],x[1]
        neigh = get_moves (xi,xj)
        for w in neigh:
            w_str = to_str(w)
            wj,wi = w[0],w[1]
            if not visited[w_str]:
                bfs_queue.append(w)
                visited[w_str] = True
                cnt_matrix[w_str] = 1 + cnt_matrix[x_str]
                if w_str in guard_set:
                    return cnt_matrix[w_str]


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

# 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)]
#
# guard_coord_str = list(map(to_str, guard_coord))
# incident_coord_str = list(map(to_str, incident_coord))

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)]


guard_coord_str = list(map(to_str, guard_coord))
incident_coord_str = list(map(to_str, incident_coord))
guard_set = set(guard_coord_str)
# print(guard_coord)
# print(guard_coord_str)
# print (guard_set)

max_y_guard = max([x[1] for x in guard_coord])
max_x_guard = max([x[0] for x in guard_coord])
max_x_incident  = max([x[0] for x in incident_coord])
max_y_incident  = max([x[1] for x in incident_coord])
max_x = max([max_x_guard, max_x_incident]) + 1
max_y = max([max_y_guard, max_y_incident]) + 1

# 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

for x,x_str in zip(incident_coord, incident_coord_str):
    if x_str in guard_set:
        print(0)
    else:
        print(BFS(x))
