#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
using P = pair<int, Pii>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}    // 右, 上, 左, 下
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int w, h, m;
    cin >> w >> h >> m;
    int px[m], py[m], qx[m], qy[m];
    set<int> xs, ys;
    xs.insert(0);
    xs.insert(w);
    ys.insert(0);
    ys.insert(h);
    for(int i=0;i<m;++i) {
        cin >> px[i] >> py[i] >> qx[i] >> qy[i];
        xs.insert(px[i]);
        ys.insert(py[i]);
        xs.insert(qx[i]);
        ys.insert(qy[i]);
    }

    int q;
    cin >> q;
    int sx[m], sy[m], gx[m], gy[m];
    for(int i=0;i<q;++i) {
        cin >> sx[i] >> sy[i] >> gx[i] >> gy[i];
        xs.insert(sx[i]);
        ys.insert(sy[i]);
        xs.insert(gx[i]);
        ys.insert(gy[i]);
    }

    map<int, int> mpx, mpy;
    {
        int i = 0;
        for(int x: xs) {
            mpx[x] = i++;
        }
    }
    {
        int i = 0;
        for(int y: ys) {
            mpy[y] = i++;
        }
    }

    bool a[2*ys.size()-1][2*xs.size()-1];
    fill_n(a[0], (2*ys.size()-1) * (2*xs.size()-1), true);
    for(int i=0;i<2*ys.size()-1;++i) {
        a[i][0] = false;
        a[i][2*xs.size()-2] = false;
    }
    for(int j=0;j<2*xs.size()-1;++j) {
        a[0][j] = false;
        a[2*ys.size()-2][j] = false;
    }
    for(int i=0;i<m;++i) {
        for(int x=2*mpx[min(px[i], qx[i])];x<=2*mpx[max(px[i], qx[i])];++x) {
            for(int y=2*mpy[min(py[i], qy[i])];y<=2*mpy[max(py[i], qy[i])];++y) {
                a[y][x] = false;
            }
        }
    }

    int nodes[2*ys.size()-1][2*xs.size()-1];
    fill_n(nodes[0], (2*ys.size()-1) * (2*xs.size()-1), 0);
    int node_i = 1;
    for(int y=1;y<2*ys.size()-2;++y) {
        for(int x=1;x<2*xs.size()-2;++x) {
            if(!a[y][x] || nodes[y][x]) continue;
            nodes[y][x] = node_i;
            queue<Pii> que;
            que.emplace(y, x);
            while(!que.empty()) {
                Pii p = que.front(); que.pop();
                for(int k=0;k<4;++k) {
                    int yy = p.first + dyx[k][0], xx = p.second + dyx[k][1];
                    if(!a[yy][xx] || nodes[yy][xx]) continue;
                    que.emplace(yy, xx);
                    nodes[yy][xx] = node_i;
                }
            }
            node_i++;
        }
    }

    set<int> graph[node_i];
    for(int y=1;y<2*ys.size()-2;++y) {
        for(int x=1;x<2*xs.size()-2;++x) {
            if(nodes[y][x]) continue;
            if(nodes[y-1][x] != 0 && nodes[y+1][x] != 0) {
                graph[nodes[y-1][x]].insert(nodes[y+1][x]);
                graph[nodes[y+1][x]].insert(nodes[y-1][x]);
            }
            if(nodes[y][x-1] != 0 && nodes[y][x+1] != 0) {
                graph[nodes[y][x-1]].insert(nodes[y][x+1]);
                graph[nodes[y][x+1]].insert(nodes[y][x-1]);
            }
        }
    }

    for(int i=0;i<q;++i) {
        int s = nodes[2*mpy[sy[i]]][2*mpx[sx[i]]];
        int g = nodes[2*mpy[gy[i]]][2*mpx[gx[i]]];
        queue<int> que;
        vector<int> dist(node_i, INF);
        que.push(s);
        dist[s] = 0;
        while(!que.empty()) {
            s = que.front(); que.pop();
            for(int t: graph[s]) {
                if(dist[t] > dist[s] + 1) {
                    dist[t] = dist[s] + 1;
                    que.push(t);
                }
            }
        }
        cout << dist[g] << endl;
    }
}



Measured memory_bytes: 5476