import sys input = sys.stdin.readline from collections import deque DP=[[1<<30]*1010 for i in range(1010)] Q=deque() N=int(input()) for i in range(N): x,y=map(int,input().split()) DP[x][y]=0 Q.append((x,y)) while Q: x,y=Q.popleft() for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z<1010 and 0<=w<1010: if DP[z][w]>DP[x][y]+1: DP[z][w]=DP[x][y]+1 Q.append((z,w)) M=int(input()) ANS=1<<30 for i in range(M): x,y=map(int,input().split()) ANS=min(ANS,DP[x][y]) print(ANS)