#include<bits/stdc++.h>
using namespace std;
#define int long long

#define MAX 111

int W, H, M, Q;
int px[MAX], py[MAX], qx[MAX], qy[MAX];
int sx[MAX], sy[MAX], gx[MAX], gy[MAX];

vector<int> X, Y;

bool hori[MAX*4][MAX*4];
bool vert[MAX*4][MAX*4];
bool used[MAX*4][MAX*4];
int color[MAX*4][MAX*4];

map<int, int> mpX, mpY;

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

vector< set<int> > graph;

signed main(){
  cin >> W >> H >> M;
  X.push_back(0);
  X.push_back(W);
  Y.push_back(0);
  Y.push_back(H);  
  for(int i = 0; i < M; i++) {
    cin >> px[i] >> py[i] >> qx[i] >> qy[i];
    X.push_back(px[i]);
    X.push_back(qx[i]);
    Y.push_back(py[i]);
    Y.push_back(qy[i]);        
  }
  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 = 0; i < X.size(); i++)cout<<X[i]<<" ";
  cout<<endl;
  for(int i = 0; i < Y.size(); i++)cout<<Y[i]<<" ";
  cout<<endl;  
  */
  for(int i = 0; i < X.size(); i++) mpX[X[i]] = i;
  for(int i = 0; i < Y.size(); i++) mpY[Y[i]] = i;
  cin >> Q;
  for(int i = 0; i < Q; i++) {
    cin >> sx[i] >> sy[i] >> gx[i] >> gy[i];
  }
  memset(hori, false, sizeof(hori));
  memset(vert, false, sizeof(vert));
  memset(used, false, sizeof(used));
  memset(color, -1, sizeof(color));
  for(int i = 0; i < M; i++) {
    if(px[i] == qx[i]) {
      if(py[i] > qy[i]) swap(py[i], qy[i]);
      for(int j = mpY[py[i]]; j < mpY[qy[i]]; j++) {
	vert[j][mpX[px[i]]] = true;
      }
    } else {
      if(px[i] > qx[i]) swap(px[i], qx[i]);
      for(int j = mpX[px[i]]; j < mpX[qx[i]]; j++) {
	hori[mpY[py[i]]][j] = true;
      }
    }
  }
  //cout<<"piyo"<<endl;
  typedef pair<int, int> P;
  int cnt = 0;
  for(int i = 0; i < Y.size()-1; i++) {
    for(int j = 0; j < X.size()-1; j++) {
      if(used[i][j]) continue;
      queue<P> que;
      que.emplace(i, j);
      used[i][j] = true;      
      color[i][j] = cnt;
      while(que.size()) {
	P p = que.front(); que.pop();
	int y = p.first, x = p.second;
	for(int k = 0; k < 4; k++) {
	  int zx = k == 2, zy = k == 3;
	  int ny = y + dy[k], nx = x + dx[k];
	  if(0 <= ny && ny < Y.size()-1 && 0 <= nx && nx < X.size()-1) {
	    if(!used[ny][nx]) {
	      if((k & 1) && !hori[ny+zy][nx+zx]) {
		que.emplace(ny, nx);
		used[ny][nx] = true;
		color[ny][nx] = cnt;
	      }
	      if(!(k & 1) && !vert[ny+zy][nx+zx]) {
		que.emplace(ny, nx);
		used[ny][nx] = true;
		color[ny][nx] = cnt;
	      }	      
	    }
	  }
	}
      }
      cnt++;
    }
  }
  graph.clear();
  graph.resize(cnt);
  for(int i = 0; i < Y.size()-1; i++) {
    for(int j = 0; j < X.size()-1; j++) {
      //if(used[i][j]) continue;      
      for(int k = 0; k < 4; k++) {
	int ny = i + dy[k], nx = j + dx[k];
	if(0 <= ny && ny < Y.size()-1 && 0 <= nx && nx < X.size()-1) {
	  if(color[i][j] != color[ny][nx]) {
	    graph[color[i][j]].insert(color[ny][nx]);
	    graph[color[ny][nx]].insert(color[i][j]);
	    //cout<<color[i][j]<<" "<<color[ny][nx]<<endl;
	  }
	}
      }      
    }
  }
  /*
  for(int i = 0; i < Y.size()-1; i++) {
    for(int j = 0; j < X.size()-1; j++) cout << color[i][j];
    cout<<endl;
  }
  cout << endl;
  for(int i = 0; i < Y.size()-1; i++) {
    for(int j = 0; j < X.size()-1; j++) cout << hori[i][j];
    cout<<endl;
  }
  cout<<endl;
  for(int i = 0; i < Y.size()-1; i++) {
    for(int j = 0; j < X.size()-1; j++) cout << vert[i][j];
    cout<<endl;
  } 
  */ 
  //exit(0);
  for(int q = 0; q < Q; q++) {
    int ty = -1, tx = -1, hy = -1, hx = -1;
    for(int i = 0; i < Y.size()-1; i++) {
      if(Y[i] <= sy[q] && sy[q] < Y[i+1]) ty = i;
      if(Y[i] <= gy[q] && gy[q] < Y[i+1]) hy = i;
    }
    for(int i = 0; i < X.size()-1; i++) {
      if(X[i] <= sx[q] && sx[q] < X[i+1]) tx = i;
      if(X[i] <= gx[q] && gx[q] < X[i+1]) hx = i;
    }
    queue<int> que;
    que.push(color[ty][tx]);
    vector<int> dist(cnt, -1);
    dist[color[ty][tx]] = 0;
    while(!que.empty()) {
      int now = que.front(); que.pop();
      //cout << now << endl;
      if(now == color[hy][hx]) {
	cout << dist[now] << endl;
	break;
      }
      for(int to : graph[now]) {
	if(~dist[to]) continue;
	dist[to] = dist[now] + 1;
	que.push(to);
      }
    }
    //cout << "hoge"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 5360