#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
  
int cnt;
int edge[1000][1000];
  
bool mas[1000][1000];
int number[1000][1000];
bool used[1000][1000];
  
const int dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};
int H, W;
  
void dfs2(int y, int x){
  if(used[y][x]++) return;
     
  for(int i = 0; i < 4; i++){
    int ny = y + dy[i], nx = x + dx[i];
    int sanoy = y - dy[i], sanox = x - dx[i];
  
    if(ny > H || ny < 0 || nx > W || nx < 0) continue;
    if(sanoy > H || sanoy < 0 || sanox > W || sanox < 0) continue;
    if(mas[ny][nx] || mas[sanoy][sanox]) continue;
  
    edge[number[ny][nx]][number[sanoy][sanox]] = 1;
    edge[number[sanoy][sanox]][number[ny][nx]] = 1;
  }
  
  for(int i = 0; i < 4; i++){
    int ny = y + dy[i], nx = x + dx[i];
    if(ny > H || ny < 0 || nx > W || nx < 0) continue;
    if(!mas[ny][nx]) continue;
    dfs2( ny, nx);
  }
  
  return;
}
void dfs(int y, int x, const int num){
  if(number[y][x] != -1) return;
  number[y][x] = num;
  
  for(int i = 0; i < 4; i++){
    int ny = y + dy[i], nx = x + dx[i];
    if(ny > H || ny < 0 || nx > W || nx < 0) continue;
    if(mas[ny][nx]) continue;
    if(number[ny][nx] == -1) dfs( ny, nx, num);
  }
  return;
}
  
pair< int, vector< int > > compress( vector< int >& x,const int w){
  vector< int > xs;
  for(int i = 0; i < x.size() ; i++ ){
    for(int d = -1; d <= 1 ; d++ ){
      int nx = x[i] + d;
      if(0 <= nx && nx < w) xs.push_back(nx);
    }
  }
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  for(int i = 0 ; i < x.size() ; i++ ){
    x[i] = lower_bound(xs.begin(),xs.end(),x[i]) - xs.begin();
  }
  return make_pair( xs.size(), xs);
}
  
int main(){
  int M;
  
  cin >> W >> H >> M;
  
  M += 4;
  vector< int > x(2 * M), y(2 * M);
  
  for(int i = 0; i < M - 4; i++){
    cin >> x[i] >> y[i] >> x[i + M] >> y[i + M];
  
    x[i] *= 2, y[i] *= 2, x[i + M] *= 2, y[i + M] *= 2;
    if(x[i] > x[i + M]) swap(x[i], x[i + M]);
    if(y[i] > y[i + M]) swap(y[i], y[i + M]);
  }
 
  x[M - 4] = W * 2, x[2 * M - 4] = W * 2;
  y[M - 4] = 0, y[2 * M - 4] = H * 2;
 
  x[M - 3] = 0, x[2 * M - 3] = W * 2;
  y[M - 3] = H * 2, y[2 * M - 3] = H * 2;
 
  x[M - 2] = 0, x[2 * M - 2] = 0;
  y[M - 2] = 0, y[2 * M - 2] = H * 2;
 
  x[M - 1] = 0, x[2 * M - 1] = W * 2;
  y[M - 1] = 0, y[2 * M - 1] = 0;
  
  pair< int , vector< int > > hoge = compress( x, 2 * W);
  pair< int , vector< int > > hoge2 = compress( y, 2 * H);
  W = hoge.first;
  H = hoge2.first;
  
  for(int i = 0; i < M; i++){
    if(y[i] == y[i + M]){
      for(int j = x[i]; j < x[i + M]; j++){
        mas[y[i]][j] = true;
      }
    } else {
      for(int j = y[i]; j < y[i + M]; j++){
        mas[j][x[i]] = true;
      }
    }
  }
 
  memset( number, -1, sizeof(number));
  cnt = 0;
  for(int i = 0; i <= H; i++){
    for(int j = 0; j <= W; j++){
      if(!mas[i][j] && number[i][j] == -1) dfs( i, j, cnt++);
    }
  }
  
  memset( used, false, sizeof(used));
  fill_n( *edge, 1000 * 1000, INF);
  
  for(int i = 0; i < M; i++){
    if(!used[y[i]][x[i]]) dfs2( y[i], x[i]);
  }
  
  for(int i = 0; i < cnt; i++){
    edge[i][i] = 0;
  }
  
  for(int k = 0; k < cnt; k++){
    for(int i = 0; i < cnt; i++){
      if(edge[i][k] == INF) continue;
      for(int j = 0; j < cnt; j++){
        if(edge[k][j] == INF) continue;
        edge[i][j] = min( edge[i][j], edge[i][k] + edge[k][j]);
      }
    }
  }
  
  int q;
  cin >> q;
  
  sort( x.begin(), x.end());
  sort( y.begin(), y.end());
  
  while(q--){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
  
    a *= 2, b *= 2, c *= 2, d *= 2;
 
    //????????£??¨??§????????¨??????
    int sx = upper_bound( hoge.second.begin(), hoge.second.end(), a) - hoge.second.begin();
    int sy = upper_bound( hoge2.second.begin(), hoge2.second.end(), b) - hoge2.second.begin();
    int gx = upper_bound( hoge.second.begin(), hoge.second.end(), c) - hoge.second.begin();
    int gy = upper_bound( hoge2.second.begin(), hoge2.second.end(), d) - hoge2.second.begin();
    cout << edge[number[sy][sx]][number[gy][gx]] << endl;
  }
}

Measured memory_bytes: 12264