#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef vector<int> vec;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const int MAX_M=100,MAX_Q=100,MAX_V=MAX_M*6;
int W,H,M,Q;
int px[MAX_M],py[MAX_M],qx[MAX_M],qy[MAX_M];
int sx[MAX_Q],sy[MAX_Q],gx[MAX_Q],gy[MAX_Q];

bool grid[(MAX_M+MAX_Q)*6][(MAX_M+MAX_Q)*6];
int grid2[(MAX_M+MAX_Q)*6][(MAX_M+MAX_Q)*6];

int V;
int G[MAX_V][MAX_V];
int dist[MAX_V];

void compress(int *x1,int *x2,int *x3,int *x4,int &w){
    vec v;
    REP(i,M){
        REP(j,3){
            int x=*(x1+i)+j-1;
            if (x>=0 && x<=w){
                v.push_back(x);
            }
            x=*(x2+i)+j-1;
            if (x>=0 && x<=w){
                v.push_back(x);
            }
        }
    }
    REP(i,Q){
        v.push_back(*(x3+i));
        v.push_back(*(x4+i));
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    REP(i,M){
        *(x1+i)=find(v.begin(),v.end(),*(x1+i))-v.begin();
        *(x2+i)=find(v.begin(),v.end(),*(x2+i))-v.begin();
    }
    REP(i,Q){
        *(x3+i)=find(v.begin(),v.end(),*(x3+i))-v.begin();
        *(x4+i)=find(v.begin(),v.end(),*(x4+i))-v.begin();
    }
    w=v.size();
}

void bfs(int s){
    queue<int> q;
    memset(dist,-1,sizeof(dist));
    dist[s]=0;
    q.push(s);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        REP(i,V){
            if (G[v][i] && dist[i]==-1){
                dist[i]=dist[v]+1;
                q.push(i);
            }
        }
    }
}

void bfs2(int x,int y){
    queue<P> q;
    q.push(P(x,y));
    grid2[x][y]=V;
    while(!q.empty()){
        P p=q.front();
        q.pop();
        REP(i,4){
            int x2=p.first+dx[i],y2=p.second+dy[i];
            if (x2<0 || x2>=W || y2<0 || y2>=H) continue;
            if (!grid[x2][y2] && grid2[x2][y2]==-1){
                grid2[x2][y2]=V;
                q.push(P(x2,y2));
            }
        }
    }
}

int main(){
    scanf("%d %d %d",&W,&H,&M);
    W*=2;
    H*=2;
    REP(i,M){
        scanf("%d %d %d %d",&px[i],&py[i],&qx[i],&qy[i]);
        if (px[i]>qx[i]){
            swap(px[i],qx[i]);
        }
        if (py[i]>qy[i]){
            swap(py[i],qy[i]);
        }
        px[i]*=2;
        py[i]*=2;
        qx[i]*=2;
        qy[i]*=2;
    }
    scanf("%d",&Q);
    REP(i,Q){
        scanf("%d %d %d %d",&sx[i],&sy[i],&gx[i],&gy[i]);
        sx[i]*=2;
        sy[i]*=2;
        gx[i]*=2;
        gy[i]*=2;
    }
    compress(px,qx,sx,gx,W);
    compress(py,qy,sy,gy,H);
    REP(i,M){
        FOR(j,px[i],qx[i]+1){
            FOR(k,py[i],qy[i]+1){
                grid[j][k]=true;
            }
        }
    }
    memset(grid2,-1,sizeof(grid2));
    REP(x,W){
        REP(y,H){
            if (!grid[x][y] && grid2[x][y]==-1){
                bfs2(x,y);
                V++;
            }
        }
    }
    REP(x,W){
        REP(y,H){
            if (grid[x][y]){
                int x2,y2,x3,y3;
                int v,u;
                x2=x-1;
                x3=x+1;
                if (x2>=0 && x3<W && !grid[x2][y] && !grid[x3][y]){
                    v=grid2[x2][y];
                    u=grid2[x3][y];
                    G[v][u]=G[u][v]=1;
                }
                y2=y-1;
                y3=y+1;
                if (y2>=0 && y3<H && !grid[x][y2] && !grid[x][y3]){
                    v=grid2[x][y2];
                    u=grid2[x][y3];
                    G[v][u]=G[u][v]=1;
                }
            }
        }
    }
    REP(i,Q){
        bfs(grid2[sx[i]][sy[i]]);
        printf("%d\n",dist[grid2[gx[i]][gy[i]]]);
    }
    return 0;
}

Measured memory_bytes: 10352