#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int W, H, N, Q;
	cin >> W >> H >> N;
	vector<int> cx = { 0, W }, cy = { 0, H };
	vector<int> ax(N), ay(N), bx(N), by(N);
	for (int i = 0; i < N; ++i) {
		cin >> ax[i] >> ay[i] >> bx[i] >> by[i];
		cx.push_back(ax[i]);
		cy.push_back(ay[i]);
		cx.push_back(bx[i]);
		cy.push_back(by[i]);
	}
	sort(cx.begin(), cx.end());
	cx.erase(unique(cx.begin(), cx.end()), cx.end());
	sort(cy.begin(), cy.end());
	cy.erase(unique(cy.begin(), cy.end()), cy.end());
	W = cx.size() - 1;
	H = cy.size() - 1;
	vector<vector<bool> > vertline(W + 1, vector<bool>(H)), horzline(W, vector<bool>(W + 1));
	for (int i = 0; i < N; ++i) {
		ax[i] = lower_bound(cx.begin(), cx.end(), ax[i]) - cx.begin();
		ay[i] = lower_bound(cy.begin(), cy.end(), ay[i]) - cy.begin();
		bx[i] = lower_bound(cx.begin(), cx.end(), bx[i]) - cx.begin();
		by[i] = lower_bound(cy.begin(), cy.end(), by[i]) - cy.begin();
		if (ax[i] > bx[i]) swap(ax[i], bx[i]);
		if (ay[i] > by[i]) swap(ay[i], by[i]);
		if (ax[i] == bx[i]) {
			for (int j = ay[i]; j < by[i]; ++j) {
				horzline[ax[i]][j] = true;
			}
		}
		if (ay[i] == by[i]) {
			for (int j = ax[i]; j < bx[i]; ++j) {
				vertline[j][ay[i]] = true;
			}
		}
	}
	cin >> Q;
	while (Q--) {
		int sx, sy, gx, gy;
		cin >> sx >> sy >> gx >> gy;
		sx = lower_bound(cx.begin(), cx.end(), sx) - cx.begin() - 1;
		sy = lower_bound(cy.begin(), cy.end(), sy) - cy.begin() - 1;
		gx = lower_bound(cx.begin(), cx.end(), gx) - cx.begin() - 1;
		gy = lower_bound(cy.begin(), cy.end(), gy) - cy.begin() - 1;
		vector<vector<int> > d(W, vector<int>(H, -1));
		d[sx][sy] = 0;
		deque<pair<int, int> > que;
		que.push_back(make_pair(sx, sy));
		while (!que.empty()) {
			pair<int, int> u = que.front(); que.pop_front();
			int cur = d[u.first][u.second];
			if (u.first >= 1 && (d[u.first - 1][u.second] == -1 || d[u.first - 1][u.second] == cur + 1)) {
				if (horzline[u.first][u.second] && d[u.first - 1][u.second] == -1) {
					d[u.first - 1][u.second] = cur + 1;
					que.push_back(make_pair(u.first - 1, u.second));
				}
				if (!horzline[u.first][u.second]) {
					d[u.first - 1][u.second] = cur;
					que.push_front(make_pair(u.first - 1, u.second));
				}
			}
			if (u.first < W - 1 && (d[u.first + 1][u.second] == -1 || d[u.first + 1][u.second] == cur + 1)) {
				if (horzline[u.first + 1][u.second] && d[u.first + 1][u.second] == -1) {
					d[u.first + 1][u.second] = cur + 1;
					que.push_back(make_pair(u.first + 1, u.second));
				}
				if (!horzline[u.first + 1][u.second]) {
					d[u.first + 1][u.second] = cur;
					que.push_front(make_pair(u.first + 1, u.second));
				}
			}
			if (u.second >= 1 && (d[u.first][u.second - 1] == -1 || d[u.first][u.second - 1] == cur + 1)) {
				if (vertline[u.first][u.second] && d[u.first][u.second - 1] == -1) {
					d[u.first][u.second - 1] = cur + 1;
					que.push_back(make_pair(u.first, u.second - 1));
				}
				if (!vertline[u.first][u.second]) {
					d[u.first][u.second - 1] = cur;
					que.push_front(make_pair(u.first, u.second - 1));
				}
			}
			if (u.second < H - 1 && (d[u.first][u.second + 1] == -1 || d[u.first][u.second + 1] == cur + 1)) {
				if (vertline[u.first][u.second + 1] && d[u.first][u.second + 1] == -1) {
					d[u.first][u.second + 1] = cur + 1;
					que.push_back(make_pair(u.first, u.second + 1));
				}
				if (!vertline[u.first][u.second + 1]) {
					d[u.first][u.second + 1] = cur;
					que.push_front(make_pair(u.first, u.second + 1));
				}
			}
		}
		cout << d[gx][gy] << endl;
	}
	return 0;
}


Measured memory_bytes: 3280