#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int field[700][700][4];

struct aa {
	int ax;
	int ay;
	int time;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
struct line {
	int px;
	int py;
	int qx;
	int qy;
	int special;
};
struct Compress {
	map<int, int>mp;
	map<int, int>revmp;

	Compress(vector<int>vs) {
		sort(vs.begin(), vs.end());
		for (int i = 0; i < vs.size(); ++i) {
			mp[vs[i]] = i+10;
			revmp[i + 10] = vs[i];
		}
	}
	Compress(const set<int>&vs) {
		int num = 10;
		for (auto v : vs) {
			mp[v] = num;
			revmp[num] = v;
			num+=2;
		}
	}
};
int memo[700][700];
int main() {
	memset(field, 0, sizeof(field));
	int W, H, M; cin >> W >> H >> M;
	set<int>xs, ys;
	vector<line>ls;
	for (int i = 0; i < M; ++i) {
		int px, py, qx, qy; cin >> px >> py >> qx >> qy;
		xs.emplace(px);
		ys.emplace(py);
		xs.emplace(qx);
		ys.emplace(qy);
		ls.push_back(line{ px,py,qx,qy,1 });
	}
	xs.emplace(0); xs.emplace(W);
	ls.push_back(line{ 0,0,W,0,10000 });
	ls.push_back(line{ 0,H,W,H,10000 });

	ys.emplace(0);ys.emplace(H);
	ls.push_back(line{ 0,0,0,H,10000 });
	ls.push_back(line{ W,0,W,H,10000 });
	Compress compx(xs);
	Compress compy(ys);
	for (auto&l : ls) {
		l.px = compx.mp[l.px];
		l.py = compy.mp[l.py];
		l.qx = compx.mp[l.qx];
		l.qy = compy.mp[l.qy];
	}
	for (auto&l : ls) {
		if (l.px == l.qx) {
			int miny = min(l.py, l.qy);
			int maxy = max(l.py, l.qy);
			for (int y = miny; y < maxy;++y) {
				field[y][l.px - 1][2] = l.special;
				field[y][l.px][0] = l.special;
			}
		}
		else {
			int minx = min(l.px, l.qx);
			int maxx = max(l.px, l.qx);
			for (int x = minx; x < maxx; ++x) {
				field[l.qy][x][3] = l.special;
				field[l.qy-1][x][1] = l.special;
			}
		}
	}
	int Q; cin >> Q;
	for (int i = 0; i < Q; ++i) {
		for (int i = 0; i < 700; ++i) {
			for (int j = 0; j < 700; ++j) {
				memo[i][j] = 100000;
			}
		}
		int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
		{
			auto it=compx.mp.lower_bound(sx);
			sx = it->second - 1;
		}
		{
			auto it = compx.mp.lower_bound(gx);
			gx = it->second  -1;
		}
		{
			auto it = compy.mp.lower_bound(sy);
			sy = it->second - 1;
		}
		{
			auto it = compy.mp.lower_bound(gy);
			gy = it->second - 1;
		}
		priority_queue<aa, vector<aa>, Compare>que;
		memo[sx][sy] = 0;

		
		que.push(aa{ sx,sy,0 });
		int ans = 0;
		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			const int nowx = atop.ax;
			const int nowy = atop.ay;
			const int nowtime = atop.time;
			if (nowx == gx&&nowy == gy) {
				ans = nowtime;
				break;
			}
			for (int way = 0; way < 4; ++way) {
				if (field[nowy][nowx][way]!=10000) {
					const int nexty = nowy + dy[way];
					const int nextx = nowx + dx[way];
					const int nexttime = nowtime + field[nowy][nowx][way];
					if (nexttime < memo[nextx][nexty]) {
						memo[nextx][nexty] = nexttime;
						que.push(aa{ nextx,nexty,nexttime });
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 12856