#include <stdio.h>
#include <string.h>
#include <algorithm>
#define Nmax 17
#define Mod 666013
#define Qmax 260
using namespace std;

int N,M,K,Q;
int a[2][Nmax][Nmax], hit[Nmax][Nmax];


int main(){
	int x,y,st,q,t,i,j,x1,y1,x2,y2,pasi;
	freopen("robotel.in","r",stdin);
	freopen("robotel.out","w",stdout);
	scanf("%d%d%d",&N,&M,&K);
	for(i=1;i<=K;++i){
		scanf("%d%d",&x,&y);
		hit[x][y]=1;
	}
	
	scanf("%d",&Q);
	for(q=1;q<=Q;++q){
		scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&pasi);
		memset(a,0,sizeof(a));
		
		if( hit[x1][y1] || hit[x2][y2] ){
			printf("0\n");
			continue;
		}
		
		st=0; 
		a[st][x1][y1]=1;
		for(t=1; t<=pasi; ++t ){
			for(i=1;i<=N;++i)
				for(j=1;j<=M;++j)
					if( hit[i][j] ) a[st^1][i][j]=0;
					else{
						a[st^1][i][j]=a[st][i-1][j];
						a[st^1][i][j]+=a[st][i][j-1];
						a[st^1][i][j]+=a[st][i+1][j];
						a[st^1][i][j]+=a[st][i][j+1];
						a[st^1][i][j] %= Mod;
					}
			st ^=1;
		}
		
		printf("%d\n",a[st][x2][y2]%Mod);
	}
	
	fclose(stdin); fclose(stdout);
	return 0;
}
