#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <queue>
#include <tuple>
#include <deque>

constexpr size_t m1 = -1;
constexpr size_t di[] = {m1, 0, 1, 0};
constexpr size_t dj[] = {0, m1, 0, 1};

void append(std::map<int, size_t>& m, int x) {
  m[x-1], m[x], m[x+1];
}

int neko(std::vector<std::string> const& s,
         size_t si, size_t sj, size_t gi, size_t gj) {

  size_t h = s.size();
  size_t w = s[0].length();

  using zahyo = std::pair<size_t, size_t>;
  int inf = 1e9;
  std::vector<std::vector<int>> dp(h, std::vector<int>(w, inf));
  dp[si][sj] = 0;
  std::deque<zahyo> q;
  q.emplace_front(si, sj);
  while (!q.empty()) {
    size_t i, j;
    std::tie(i, j) = q.front();
    q.pop_front();
    bool breakable = (s[i][j] == '.');
    for (int k = 0; k < 4; ++k) {
      size_t ni = i + di[k];
      size_t nj = j + dj[k];
      if (!(ni < h && nj < w)) continue;
      int cost = 0;
      if (s[ni][nj] == '#') {
        if (!breakable) continue;
        cost = 1;
      }
      if (dp[ni][nj] > dp[i][j] + cost) {
        dp[ni][nj] = dp[i][j] + cost;
        if (cost == 0) {
          q.emplace_front(ni, nj);
        } else {
          q.emplace_back(ni, nj);
        }
        if (ni == gi && nj == gj) {
          // for (size_t i = 0; i < h; ++i)
          //   for (size_t j = 0; j < w; ++j) {
          //     if (dp[i][j] == inf) fprintf(stderr, "##");
          //     else fprintf(stderr, "%2d", dp[i][j]);
          //     fprintf(stderr, "%c", j+1<w? ' ':'\n');
          //   }
          return dp[ni][nj];
        }
      }
    }
  }

  assert(false);
  // return dp[gi][gj];
}

int main() {
  size_t h, w, m;
  scanf("%zu %zu %zu", &w, &h, &m);

  std::map<int, size_t> xs, ys;
  std::vector<int> px(m), py(m), qx(m), qy(m);
  xs[0], xs[2*w], ys[0], ys[2*h];
  for (size_t i = 0; i < m; ++i) {
    scanf("%d %d %d %d", &px[i], &py[i], &qx[i], &qy[i]);
    if (px[i] > qx[i]) std::swap(px[i], qx[i]);
    if (py[i] > qy[i]) std::swap(py[i], qy[i]);
    px[i] *= 2;
    py[i] *= 2;
    qx[i] *= 2;
    qy[i] *= 2;
  }

  size_t q;
  scanf("%zu", &q);
  std::vector<int> sx(q), sy(q), gx(q), gy(q);
  for (size_t i = 0; i < q; ++i) {
    scanf("%d %d %d %d", &sx[i], &sy[i], &gx[i], &gy[i]);
    // if (sx[i] > gx[i]) std::swap(sx[i], gx[i]);
    // if (sy[i] > gy[i]) std::swap(sy[i], gy[i]);
    sx[i] *= 2;
    sy[i] *= 2;
    gx[i] *= 2;
    gy[i] *= 2;
  }

  for (auto const& x: px) append(xs, x);
  for (auto const& x: qx) append(xs, x);
  for (auto const& x: sx) append(xs, x);
  for (auto const& x: gx) append(xs, x);

  for (auto const& y: py) append(ys, y);
  for (auto const& y: qy) append(ys, y);
  for (auto const& y: sy) append(ys, y);
  for (auto const& y: gy) append(ys, y);

  {
    size_t i = 0;
    for (auto& p: xs) p.second = i++;
    // for (auto& p: xs) {
    //   fprintf(stderr, "x: %d -> %zu\n", p.first, p.second);
    // }
  }
  {
    size_t i = 0;
    for (auto& p: ys) p.second = i++;
    // for (auto& p: ys) {
    //   fprintf(stderr, "y: %d -> %zu\n", p.first, p.second);
    // }
  }

  size_t hh = ys.size();
  size_t ww = xs.size();
  std::vector<std::string> s(hh, std::string(ww, '.'));
  for (size_t i = 0; i < m; ++i) {
    size_t pi = ys.at(py[i]);
    size_t pj = xs.at(px[i]);
    size_t qi = ys.at(qy[i]);
    size_t qj = xs.at(qx[i]);
    for (size_t ii = pi; ii <= qi; ++ii)
      for (size_t jj = pj; jj <= qj; ++jj)
        s[ii][jj] = '#';
  }

  s[ys.at(0)] = s[ys.at(2*h)] = std::string(ww, '#');
  s[0] = s[hh-1] = std::string(ww, '#');
  for (size_t i = 0; i < hh; ++i) {
    s[i][xs.at(0)] = s[i][xs.at(2*w)] = '#';
    s[i][0] = s[i][ww-1] = '#';
  }

  // for (size_t i = 0; i < hh; ++i)
  //   fprintf(stderr, "%s\n", s[i].c_str());

  for (size_t i = 0; i < q; ++i) {
    int res = neko(s, ys.at(sy[i]), xs.at(sx[i]), ys.at(gy[i]), xs.at(gx[i]));
    printf("%d\n", res);
  }
}



Measured memory_bytes: 9728