#include <algorithm>
#include <cstdio>
using namespace std;

#define MOD 666013
#define MAX 260
#define DIM 20

int dx[4]={1,0,-1, 0};
int dy[4]={0,1, 0,-1};

struct query
{
    int xi,yi,xf,yf,t,ind;
};

int bst[2][DIM][DIM];
query v[MAX],w[MAX];
bool bad[DIM][DIM];
int K,N,M,P,Q;
int sol[MAX];

void read ()
{
    int i,x,y;

    scanf ("%d%d%d",&N,&M,&K);
    for (i=1; i<=K; ++i)
    {
        scanf ("%d%d",&x,&y);
        bad[x][y]=1;
    }

    scanf ("%d",&P);
    for (i=1; i<=P; ++i)
    {
        scanf ("%d%d%d%d%d",&v[i].xi,&v[i].yi,&v[i].xf,&v[i].yf,&v[i].t);
        v[i].ind=i;
    }
}

struct cmp_v
{
    bool operator () (const query &a,const query &b)
    {
        if (a.xi==b.xi)
            return a.yi<b.yi;

        return a.xi<b.xi;
    }
};

struct cmp_w
{
    bool operator () (const query &a,const query &b)
    {
        return a.t<b.t;
    }
};

inline void solve_dp ()
{
    int i1,i2,i,j,k,l,q,xi,yi,t_max;

    for (i=1; i<=N; ++i)
        for (j=1; j<=M; ++j)
            bst[0][i][j]=0;

    t_max=w[Q].t; xi=w[1].xi; yi=w[1].yi;
    bst[0][xi][yi]=1;

    q=1; i1=0; i2=1;
    for (k=1; k<=t_max; ++k)
    {
        for (i=1; i<=N; ++i)
            for (j=1; j<=M; ++j)
            {
                bst[i2][i][j]=0;
                if (!bad[i][j])
                    for (l=0; l<4; ++l)
                    {
                        bst[i2][i][j]+=bst[i1][i+dx[l]][j+dy[l]];
                        if (bst[i2][i][j]>=MOD)
                            bst[i2][i][j]-=MOD;
                    }
            }

        for ( ; w[q].t==k; ++q)
            sol[w[q].ind]=bst[i2][w[q].xf][w[q].yf];

        i1^=1; i2^=1;
    }
}

void solve ()
{
    int i;

    sort (v+1,v+P+1,cmp_v ());
    for (i=1; i<=P; i+=Q)
    {
        for (Q=1; v[i].xi==v[i+Q-1].xi && v[i].yi==v[i+Q-1].yi; ++Q)
            w[Q]=v[i+Q-1];
        --Q;

        sort (w+1,w+Q+1,cmp_w ());
        solve_dp ();
    }

    for (i=1; i<=P; ++i)
        printf ("%d\n",sol[i]);
}

int main ()
{
    freopen ("robotel.in","r",stdin);
    freopen ("robotel.out","w",stdout);

    read ();
    solve ();

    return 0;
}
