#include<bits/stdc++.h>
using namespace std;
struct Segment {
  int x1, y1, x2, y2;
  Segment(int x1, int y1, int x2, int y2):x1(x1), y1(y1), x2(x2), y2(y2){};
};
bool mas[1000][1000], used[1000][1000];
int number[1000][1000], edge[400][400];
const int INF = 1 << 28;
static const int dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};

inline void dfs(int x, int y, const int& num) {
  if(number[y][x] != -1 || mas[y][x]) return;
  number[y][x] = num;
  for(int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i], num);
}

inline void dfs2(int x, int y, const int& W, const int& H) {
  if(used[y][x]++) return;
  for(int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    int vx = x - dx[i], vy = y - dy[i];
    if(nx < 0 || nx > W || ny < 0 || ny > H) continue;
    if(mas[ny][nx]) dfs2(nx, ny, W, H);
    if(vx < 0 || vx > W || vy < 0 || vy > H) continue;
    if(mas[ny][nx] || mas[vy][vx]) continue;
    edge[number[ny][nx]][number[vy][vx]] = 1;
  }
}


int main() {
  int W, H, M, Q;
  vector< Segment > Wall;

  scanf("%d %d %d", &W, &H, &M);
  for(int i = 0; i < M; i++){ 
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    Wall.push_back(Segment(x1 << 1, y1 << 1, x2 << 1, y2 << 1));
  }
  Wall.push_back(Segment(0 << 1, 0 << 1, 0 << 1, H << 1));
  Wall.push_back(Segment(0 << 1, 0 << 1, W << 1, 0 << 1));
  Wall.push_back(Segment(0 << 1, H << 1, W << 1, H << 1));
  Wall.push_back(Segment(W << 1, 0 << 1, W << 1, H << 1));

  W <<= 1, H <<= 1;
  vector< int > numX, numY;
  for(int i = 0; i < Wall.size(); i++) {
    for(int j = -1; j <= 1; j++) {
      if(0 <= Wall[i].x1 + j && Wall[i].x1 + j <= W) numX.push_back(Wall[i].x1 + j);
      if(0 <= Wall[i].x2 + j && Wall[i].x2 + j <= W) numX.push_back(Wall[i].x2 + j);
      if(0 <= Wall[i].y1 + j && Wall[i].y1 + j <= H) numY.push_back(Wall[i].y1 + j);
      if(0 <= Wall[i].y2 + j && Wall[i].y2 + j <= H) numY.push_back(Wall[i].y2 + j);
    }
  }
  sort(numX.begin(), numX.end());
  numX.erase(unique(numX.begin(), numX.end()), numX.end());
  sort(numY.begin(), numY.end());
  numY.erase(unique(numY.begin(), numY.end()), numY.end());

  for(int i = 0; i < Wall.size(); i++) {
    Segment& p = Wall[i];
    p.x1 = lower_bound(numX.begin(), numX.end(), p.x1) - numX.begin();
    p.x2 = lower_bound(numX.begin(), numX.end(), p.x2) - numX.begin();
    p.y1 = lower_bound(numY.begin(), numY.end(), p.y1) - numY.begin();
    p.y2 = lower_bound(numY.begin(), numY.end(), p.y2) - numY.begin();
    if(p.x1 == p.x2) {
      for(int j = min(p.y1, p.y2); j < max(p.y1, p.y2); j++) {
        mas[j][p.x1] = true;
      }
    } else {
      for(int j = min(p.x1, p.x2); j < max(p.x1, p.x2); j++) {
        mas[p.y1][j] = true;
      }
    }
  }

  H = numY.size() - 1; W = numX.size() - 1;
  int size = 0;
  fill_n(*number, 1000 * 1000, -1);
  for(int i = 1; i < H; i++) {
    for(int j = 1; j < W; j++) {
      if(!mas[i][j] && number[i][j] == -1) dfs(j, i, size++);
    }
  }
  fill_n(*edge, 400 * 400, INF);
  for(int i = 0; i < Wall.size(); i++) {
    if(!used[Wall[i].y1][Wall[i].x1]) {
      dfs2(Wall[i].x1, Wall[i].y1, W, H);
    }
  }

  for(int k = 0; k < size; k++) {
    edge[k][k] = 0;
    for(int i = 0; i < size; i++) {
      for(int j = 0; j < size; j++) {
        edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
      }
    }
  }

  scanf("%d", &Q);
  while(Q--){ 
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int sx = upper_bound(numX.begin(), numX.end(), a << 1) - numX.begin();
    int sy = upper_bound(numY.begin(), numY.end(), b << 1) - numY.begin();
    int gx = upper_bound(numX.begin(), numX.end(), c << 1) - numX.begin();
    int gy = upper_bound(numY.begin(), numY.end(), d << 1) - numY.begin();
    printf("%d\n", edge[number[sy][sx]][number[gy][gx]]);
  }
}
  

Measured memory_bytes: 7912