#include <cstdio>
#include <cstring>
#define NMAX 16
#define LMAX 22
#define HMAX 255
#define ll long long
#define MOD 666013
int n,m,k,q,r,t,x1,y1,x2,y2;
int rez[NMAX][NMAX],aux[NMAX][NMAX];
char marc[NMAX][NMAX];
int A[LMAX][NMAX][NMAX][NMAX][NMAX];
int dlin[]={0,0,-1,1};
int dcol[]={-1,1,0,0};
struct pereche{int a,b;};
pereche B[HMAX];
void read()
{
	scanf("%d%d%d",&n,&m,&k);
	int i,j,x,y;
	for (i=1; i<=k; i++)
	{
		scanf("%d%d",&x,&y);
		marc[x][y]=1;
	}
	for (i=1; i<=n; i++)
		for (j=1; j<=m; j++)
			if (!marc[i][j])
				B[++r].a=i,B[r].b=j;
}
inline int ok(int x,int y)
{
	return 1<=x && x<=n && 1<=y && y<=m;
}
void precompute()
{
	int i,j,k,x,xn,yn;
	for (i=1; i<=n; i++)
		for (j=1; j<=m; j++)
			for (k=0; k<4; k++)
			{
				xn=i+dlin[k]; yn=j+dcol[k];
				if (ok(xn,yn) && !marc[xn][yn] && !marc[i][j])
					A[0][i][j][xn][yn]=1;
			}
	for (x=1; x<=20; x++)
	{
		for (i=1; i<=r; i++)
			for (j=1; j<=r; j++)
				for (k=1; k<=r; k++)
				{
					A[x][B[i].a][B[i].b][B[j].a][B[j].b]+=((ll)A[x-1][B[i].a][B[i].b][B[k].a][B[k].b]*
															A[x-1][B[k].a][B[k].b][B[j].a][B[j].b])%MOD;
					if (A[x][B[i].a][B[i].b][B[j].a][B[j].b]>=MOD)
						A[x][B[i].a][B[i].b][B[j].a][B[j].b]-=MOD;
				}
	}
}
void solve()
{
	scanf("%d",&q);
	int i,j,x,y;
	for (i=1; i<=q; i++)
	{
		scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&t);
		if (marc[x1][y1] || marc[x2][y2])
		{
			printf("0\n");
			continue ;
		}
		memset(rez,0,sizeof(rez));
		rez[x1][y1]=1;
		for (j=0; j<20; j++)
			if (t & (1<<j))
			{
				memset(aux,0,sizeof(aux));
				for (x=1; x<=r; x++)
					for (y=1; y<=r; y++)
					{
						aux[B[y].a][B[y].b]+=((ll)rez[B[x].a][B[x].b]*A[j][B[x].a][B[x].b][B[y].a][B[y].b])%MOD;
						if (aux[B[y].a][B[y].b]>=MOD)
							aux[B[y].a][B[y].b]-=MOD;
					}
				memcpy(rez,aux,sizeof(aux));
			}
		printf("%d\n",rez[x2][y2]);
	}
}
int main()
{
	freopen("robotel.in","r",stdin);
	freopen("robotel.out","w",stdout);
	read();
	precompute();
	solve();
	return 0;
}
