#include using namespace std; const int N = 1e3 + 5; const int M = 2e5 + 5; struct Node{ int x, y, cnt; }que[N * N]; int n, m, head = 1, tail, dist[N][N]; bool vis[N][M]; pair a[M]; void Record(int x, int y, int cnt){ if(x < 0 || x >= N - 5 || y < 0 || y >= N - 5 || vis[x][y]) return ; dist[x][y] = cnt, vis[x][y] = 1; que[++tail] = {x, y, cnt}; } int main(){ cin >> n; for(int i = 0; i < N - 5; i++){ for(int j = 0; j < N - 5; j++) dist[i][j] = N * N + N * N; } for(int i = 1, x, y; i <= n; i++){ cin >> x >> y; Record(x, y, 0); } cin >> m; for(int i = 1; i <= m; i++){ cin >> a[i].first >> a[i].second; } while(head <= tail){ Node q = que[head++]; Record(q.x - 1, q.y, q.cnt + 1); Record(q.x + 1, q.y, q.cnt + 1); Record(q.x, q.y - 1, q.cnt + 1); Record(q.x, q.y + 1, q.cnt + 1); } int ans = INT_MAX; for(int i = 1; i <= m; i++){ ans = min(ans, dist[a[i].first][a[i].second]); } cout << ans; return 0; }