#include using namespace std; using pii = pair; const int N = 2e5 + 10, M = 1e3 + 10; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; int n, x[N], y[N], m, z[N], w[N], d[M][M], ans = 2 * M; queue que; void Record(int x, int y, int dis) { if (x < 0 || x >= M || y < 0 || y >= M || d[x][y]) return ; d[x][y] = dis, que.push({x, y}); } void bfs() { for (int i = 1; i <= n; i++) Record(x[i], y[i], 1); while (!que.empty()) { auto [x, y] = que.front(); que.pop(); for (int i = 0; i < 4; i++) Record(x + dx[i], y + dy[i], d[x][y] + 1); } } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; cin >> m; for (int i = 1; i <= m; i++) cin >> z[i] >> w[i]; bfs(); for (int i = 1; i <= m; i++) ans = min(ans, d[z[i]][w[i]] - 1); cout << ans; return 0; }