#include<cstdio>
#define mod 666013
using namespace std;


int sol[7][7][150000],i,j;
bool us[15][15];
int n,m,p,k,t;

void solve(int xi,int yi){
sol[xi][yi][0] = 1;
int i,j,k;

for( k = 1 ;k<=t;k++)
	for(i = 1 ; i <= n ;i++)
		for(j = 1 ; j <= m; j++)
			if(!us[i][j])
				{sol[i][j][k] = sol[i-1][j][k-1]+sol[i][j-1][k-1]+sol[i+1][j][k-1]+sol[i][j+1][k-1];
				if(sol[i][j][k] >= mod)
					sol[i][j][k] %= mod;
				}
}

void citire(){
freopen("robotel.in","r",stdin);

scanf("%d %d %d",&n,&m,&k);
int x,y;
for(i = 1; i <= k ; i++)
	{scanf("%d %d",&x,&y);
	us[x][y] = true;
	}
scanf("%d",&p);
int xi,yi,xf,yf;
freopen("robotel.out","w",stdout);
for(i = 1 ;i <= p;i++)
	{scanf("%d %d %d %d %d",&xi,&yi,&xf,&yf,&t);
	solve(xi,yi);
	printf("%d\n",sol[xf][yf][t]);
	sol[xi][yi][0] = 0;
	}
}	

int main(){
citire();
return 0;}

