#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;

#define Nmax 110
#define MOD 666013

int n, m, k, N;
int viz[Nmax];

int Dx[4] = {0, -1, 0, 1};
int Dy[4] = {1, 0, -1, 0};

int A[Nmax][Nmax], R[Nmax][Nmax], B[Nmax][Nmax];

void inm1 () {
	
	long long C[Nmax][Nmax];
	int i, j, k;

	for (i = 0; i <= N; i++)
		for (j = 0; j <= N; j++) {
			C[i][j] = 0;
			if (!viz[i] && !viz[j]) {
				for (k = 0; k <= N; k++) {
					C[i][j]+= (long long)R[i][k] * (long long)B[k][j];
					//C[i][j]%= MOD;
				}
			}
			
			C[i][j]%= (long long) MOD;
		}
	
	for (i = 0; i <= N; i++)
		for (j = 0; j <= N; j++)
			R[i][j] = (int)C[i][j];
}

void inm2 () {
	
	long long C[Nmax][Nmax];
	int i, j, k;

	for (i = 0; i <= N; i++)
		for (j = 0; j <= N; j++) {
			C[i][j] = 0;
			if (!viz[i] && !viz[j]) {	
				for (k = 0; k <= N; k++) {
					C[i][j]+= (long long)B[i][k] * (long long)B[k][j];
					//C[i][j]%= MOD;
				}
			}
			
			C[i][j]%= (long long) MOD;
		}
	
	for (i = 0; i <= N; i++)
		for (j = 0; j <= N; j++)
			B[i][j] = (int)C[i][j];
}

void ridica (int T) {
	
	int i, j;
	for (i = 0; i <= N; i++)
		for (j = 0 ; j <= N; j++) {
			B[i][j] = A[i][j];
			R[i][j] = 0;
			if (i == j) R[i][j] = 1;  
		}
	
	for (; T; T>>=1) {
		if (T&1) inm1 ();
		inm2 ();
	}
}

void rezolva () {
	
	int Q, x1, y1, x2, y2, nod1, nod2, T;
	scanf ("%d", &Q);
	for (; Q; Q--) {
		scanf ("%d %d %d %d %d", &x1, &y1, &x2, &y2, &T);
		nod1 = (x1-1) * n + (y1-1) % m;
		nod2 = (x2-1) * n + (y2-1) % m;
		
		ridica (T);
		printf ("%d\n", R[nod1][nod2]);
	}
}

void citire () {
	
	int i, j, x, y, nod, d, fiu;
	
	scanf ("%d %d %d", &n, &m, &k);
	for (i = 1; i <= k; i++) {
		scanf ("%d %d", &x, &y);
		nod = (x-1) * n + (y-1) % m;
		viz[nod] = 1;
	}
	
	N = (n-1) * m + (m - 1);
	for (i = 1; i <= n; i++) 
		for (j = 1; j <= m; j++) {
			nod = (i-1) * n + (j-1) % m;
			
			for (d = 0; d <= 3; d++) {
				x = i + Dx[d];
				y = j + Dy[d];
				
				if (x > 0 && x <= n && y > 0 && y <= m) {
					fiu = (x-1) * n + (y-1) % m;
					if (!viz[nod] && !viz[fiu])A[nod][fiu]= 1;
				}
			}
		}
}

int main () {

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

	citire ();
	rezolva ();
	
	return 0;
}
