#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	void set(int arg_row1,int arg_row2,int arg_col1,int arg_col2){
		row1 = arg_row1;
		row2 = arg_row2;
		col1 = arg_col1;
		col2 = arg_col2;
	}
	int row1,row2,col1,col2;
};

struct Data{
	bool right_wall,under_wall;
};

struct State{
	State(int arg_row,int arg_col,int arg_sum_cost){
		row = arg_row;
		col = arg_col;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct State &arg) const{ //壁を越えた回数の昇順(PQ)
		return sum_cost > arg.sum_cost;
	}

	int row,col,sum_cost;
};

int comp_H,comp_W; //座標圧縮後の高さと幅
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
int min_cost[500][500];
Info wall[100],query[100];
Data table[500][500];

bool rangeCheck(int row,int col){
	if(row >= 2 && row <= comp_H-2 && col >= 2 && col <= comp_W-2)return true;
	else{
		return false;
	}
}

int main(){

	int W,H,M;
	scanf("%d %d %d",&W,&H,&M);

	vector<int> ROW,COL;

	/*★外枠に注意!!★*/
	ROW.push_back(0);
	ROW.push_back(H);
	ROW.push_back(-BIG_NUM);
	ROW.push_back(BIG_NUM);

	COL.push_back(0);
	COL.push_back(W);
	COL.push_back(-BIG_NUM);
	COL.push_back(BIG_NUM);

	int row1,row2,col1,col2;
	for(int i = 0; i < M; i++){

		scanf("%d %d %d %d",&col1,&row1,&col2,&row2);

		if(row1 > row2)swap(row1,row2);
		if(col1 > col2)swap(col1,col2);

		wall[i].set(row1,row2,col1,col2);

		ROW.push_back(row1);
		ROW.push_back(row2);
		COL.push_back(col1);
		COL.push_back(col2);
	}

	int num_query;
	scanf("%d",&num_query);

	for(int i = 0; i < num_query; i++){
		scanf("%d %d %d %d",&query[i].col1,&query[i].row1,&query[i].col2,&query[i].row2);

		ROW.push_back(query[i].row1);
		ROW.push_back(query[i].row2);
		COL.push_back(query[i].col1);
		COL.push_back(query[i].col2);
	}

	sort(ROW.begin(),ROW.end());
	sort(COL.begin(),COL.end());

	ROW.erase(unique(ROW.begin(),ROW.end()),ROW.end());
	COL.erase(unique(COL.begin(),COL.end()),COL.end());

	map<int,int> INDEX_ROW,INDEX_COL;
	for(int i = 0; i < ROW.size(); i++){
		INDEX_ROW[ROW[i]] = i;
	}

	for(int i = 0; i < COL.size(); i++){
		INDEX_COL[COL[i]] = i;
	}

	//座標変換
	for(int i = 0; i < M; i++){
		wall[i].row1 = INDEX_ROW[wall[i].row1];
		wall[i].row2 = INDEX_ROW[wall[i].row2];
		wall[i].col1 = INDEX_COL[wall[i].col1];
		wall[i].col2 = INDEX_COL[wall[i].col2];
	}

	for(int i = 0; i < num_query; i++){
		query[i].row1 = INDEX_ROW[query[i].row1];
		query[i].row2 = INDEX_ROW[query[i].row2];
		query[i].col1 = INDEX_COL[query[i].col1];
		query[i].col2 = INDEX_COL[query[i].col2];
	}

	comp_H = ROW.size(),comp_W = COL.size();

	for(int row = 0; row < comp_H;row++){
		for(int col = 0; col < comp_W; col++){
			table[row][col].right_wall = false;
			table[row][col].under_wall = false;
		}
	}

	//外壁の情報を設定

	//上
	for(int col = 0; col < comp_W; col++){
		table[1][col].under_wall = true;
	}

	//左
	for(int row = 0; row < comp_H; row++){
		table[row][1].right_wall = true;
	}

	//下
	for(int col = 0; col < comp_W; col++){
		table[comp_H-2][col].under_wall = true;
	}

	//右
	for(int row = 0; row < comp_H; row++){
		table[row][comp_W-2].right_wall = true;
	}

	for(int i = 0; i < M; i++){
		if(wall[i].row1 == wall[i].row2){ //横線

			for(int col = wall[i].col1+1; col <= wall[i].col2; col++){
				table[wall[i].row1][col].under_wall = true;
			}
		}else{ //縦線

			for(int row = wall[i].row1+1; row <= wall[i].row2; row++){
				table[row][wall[i].col1].right_wall = true;
			}
		}
	}

	priority_queue<State> Q;
	int adj_row,adj_col,next_cost,add_cost;

	for(int i = 0; i < num_query; i++){
		for(int row = 0; row < comp_H; row++){
			for(int col = 0; col < comp_W; col++)min_cost[row][col] = BIG_NUM;
		}

		while(!Q.empty())Q.pop();

		min_cost[query[i].row1][query[i].col1] = 0;
		Q.push(State(query[i].row1,query[i].col1,0));

		while(!Q.empty()){
			if(Q.top().row == query[i].row2 && Q.top().col == query[i].col2){
				printf("%d\n",Q.top().sum_cost);
				break;
			}else if(Q.top().sum_cost > min_cost[Q.top().row][Q.top().col]){
				Q.pop();
			}else{

				for(int i = 0; i < 4; i++){
					adj_row = Q.top().row+diff_row[i];
					adj_col = Q.top().col+diff_col[i];

					if(!rangeCheck(adj_row,adj_col))continue;

					add_cost = 0;
					switch(i){
					case 0: //上
						if(table[adj_row][adj_col].under_wall)add_cost++;
						break;
					case 1: //左
						if(table[adj_row][adj_col].right_wall)add_cost++;
						break;
					case 2: //右
						if(table[Q.top().row][Q.top().col].right_wall)add_cost++;
						break;
					case 3: //下
						if(table[Q.top().row][Q.top().col].under_wall)add_cost++;
						break;
					}

					next_cost = Q.top().sum_cost+add_cost;
					if(min_cost[adj_row][adj_col] > next_cost){
						min_cost[adj_row][adj_col] = next_cost;
						Q.push(State(adj_row,adj_col,next_cost));
					}
				}
				Q.pop();
			}
		}
	}

	return 0;
}



Measured memory_bytes: 4416