#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

int H, W, N, Q, px[109], py[109], qx[109], qy[109], sx[109], sy[109], gx[109], gy[109], dist[10009];
vector<int>X, Y; bool wall[1009][1009]; int col[1009][1009], cntw; vector<int>G[10009]; map<pair<int, int>, int>M;

void dfs(int cx, int cy) {
	col[cx][cy] = cntw;
	int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
	for (int i = 0; i < 4; i++) {
		int fx = cx + dx[i], fy = cy + dy[i];
		if (fx < 0 || fy < 0 || fx >= X.size() || fy >= Y.size() || wall[fx][fy] == true || col[fx][fy] >= 1) continue;
		dfs(fx, fy);
	}
}
int solve(int cx, int cy) {
	for (int i = 0; i < 10009; i++)dist[i] = 9999999;
	queue<int>q; q.push(cx); dist[cx] = 0;
	while (!q.empty()) {
		int to1 = q.front(); q.pop();
		for (int i : G[to1]) {
			if (dist[i] > dist[to1] + 1) {
				dist[i] = dist[to1] + 1; q.push(i);
			}
		}
	}
	return dist[cy];
}

int main() {
	cin >> H >> W >> N;
	for (int i = 1; i <= N; i++) cin >> px[i] >> py[i] >> qx[i] >> qy[i];
	cin >> Q;
	for (int i = 1; i <= Q; i++) cin >> sx[i] >> sy[i] >> gx[i] >> gy[i];
	for (int i = 1; i <= N; i++) {
		px[i] *= 2; py[i] *= 2; qx[i] *= 2; qy[i] *= 2;
		if (px[i] > qx[i]) swap(px[i], qx[i]); if (py[i] > qy[i]) swap(py[i], qy[i]);
		if (px[i] >= 1) X.push_back(px[i] - 1); X.push_back(px[i]); if (px[i] < H * 2) X.push_back(px[i] + 1);
		if (qx[i] >= 1) X.push_back(qx[i] - 1); X.push_back(qx[i]); if (qx[i] < H * 2) X.push_back(qx[i] + 1);
		if (py[i] >= 1) Y.push_back(py[i] - 1); Y.push_back(py[i]); if (py[i] < W * 2) Y.push_back(py[i] + 1);
		if (py[i] >= 1) Y.push_back(qy[i] - 1); Y.push_back(qy[i]); if (qy[i] < W * 2) Y.push_back(qy[i] + 1);
	}
	for (int i = 1; i <= Q; i++) {
		sx[i] *= 2; sy[i] *= 2; gx[i] *= 2; gy[i] *= 2;
		X.push_back(sx[i]); Y.push_back(sy[i]);
		X.push_back(gx[i]); Y.push_back(gy[i]);
	}
	X.push_back(0); Y.push_back(0); X.push_back(H * 2); Y.push_back(W * 2);
	sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end());
	sort(Y.begin(), Y.end()); Y.erase(unique(Y.begin(), Y.end()), Y.end());
	for (int i = 1; i <= N; i++) {
		px[i] = lower_bound(X.begin(), X.end(), px[i]) - X.begin();
		qx[i] = lower_bound(X.begin(), X.end(), qx[i]) - X.begin();
		py[i] = lower_bound(Y.begin(), Y.end(), py[i]) - Y.begin();
		qy[i] = lower_bound(Y.begin(), Y.end(), qy[i]) - Y.begin();
		if (px[i] == qx[i]) {
			for (int j = py[i]; j <= qy[i]; j++) wall[px[i]][j] = true;
		}
		if (py[i] == qy[i]) {
			for (int j = px[i]; j <= qx[i]; j++) wall[j][py[i]] = true;
		}
	}
	for (int i = 0; i < Y.size(); i++) wall[0][i] = true;
	for (int i = 0; i < Y.size(); i++) wall[X.size() - 1][i] = true;
	for (int i = 0; i < X.size(); i++) wall[i][0] = true;
	for (int i = 0; i < X.size(); i++) wall[i][Y.size() - 1] = true;
	for (int i = 1; i <= Q; i++) {
		sx[i] = lower_bound(X.begin(), X.end(), sx[i]) - X.begin();
		gx[i] = lower_bound(X.begin(), X.end(), gx[i]) - X.begin();
		sy[i] = lower_bound(Y.begin(), Y.end(), sy[i]) - Y.begin();
		gy[i] = lower_bound(Y.begin(), Y.end(), gy[i]) - Y.begin();
	}
	for (int i = 0; i < X.size(); i++) {
		for (int j = 0; j < Y.size(); j++) {
			if (wall[i][j] == true || col[i][j] >= 1) continue;
			cntw++; dfs(i, j);
		}
	}
	for (int i = 0; i < (int)X.size(); i++) {
		for (int j = 0; j < (int)Y.size() - 2; j++) {
			if (wall[i][j] == false && wall[i][j + 1] == true && wall[i][j + 2] == false && col[i][j] != col[i][j + 2]) {
				int d1 = col[i][j], d2 = col[i][j + 2];
				if (M[make_pair(d1, d2)] == 1) continue;
				M[make_pair(d1, d2)] = 1; G[d1].push_back(d2);
				M[make_pair(d2, d1)] = 1; G[d2].push_back(d1);
			}
		}
	}
	for (int i = 0; i < (int)Y.size(); i++) {
		for (int j = 0; j < (int)X.size() - 2; j++) {
			if (wall[j][i] == false && wall[j + 1][i] == true && wall[j + 2][i] == false && col[j][i] != col[j + 2][i]) {
				int d1 = col[j][i], d2 = col[j + 2][i];
				if (M[make_pair(d1, d2)] == 1) continue;
				M[make_pair(d1, d2)] = 1; G[d1].push_back(d2);
				M[make_pair(d2, d1)] = 1; G[d2].push_back(d1);
			}
		}
	}
	/*for (int i = 0; i < X.size(); i++) {
		for (int j = 0; j < Y.size(); j++) cout << (int)wall[i][j] << " "; cout << endl;
	}
	cout << endl;
	for (int i = 0; i < X.size(); i++) {
		for (int j = 0; j < Y.size(); j++) cout << col[i][j] << " "; cout << endl;
	}*/
	for (int i = 1; i <= Q; i++) {
		cout << solve(col[sx[i]][sy[i]], col[gx[i]][gy[i]]) << endl;
	}
	return 0;
}


Measured memory_bytes: 11560