#include <cstdio>
#include <vector>

using namespace std;

#define NMAX 20
#define MOD 666013

int A[NMAX][NMAX];
int V[NMAX][NMAX], n, m, k, p, t, x1, y1, x2, y2;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
vector < pair <int, int> > L, T;

int query () {
	
	int i, j, x, y, k, d;
	vector < pair <int, int> >::iterator it;
	
	if (A[x1][y1] == 1 || A[x2][y2] == 1) return 0;
	
	memset (V, 0, sizeof (V)); L.clear (), T.clear ();
	
	V[x1][y1] = 1; L.push_back (make_pair (x1, y1));
	for (k = 1; k <= t; k++) {
		for (it = L.begin (); it != L.end (); it++) {
			i = it -> first, j = it -> second;
			for (d = 0; d < 4; d++) {
				x = i + dx[d], y = j + dy[d];
				if (!A[x][y] && x > 0 && x <= n && y > 0 && y <= m) {
					V[x][y] += V[i][j];
					if (V[x][y] >= MOD) V[x][y] -= MOD;
					T.push_back (make_pair (x, y));
				}
			}
			
			V[i][j] = 0;
		}
		
		L.swap (T); T.clear ();
	}
	
	return V[x2][y2];
}

int main () {
	
	freopen ("robotel.in", "r", stdin);
	freopen ("robotel.out", "w", stdout);
	
	scanf ("%d %d %d", &n, &m, &k);
	
	int i, x, y;
	for (i = 1; i <= k; i++) {
		scanf ("%d %d", &x, &y);
		A[x][y] = 1;
	}
	
	scanf ("%d", &p);
	
	for (i = 1; i <= p; i++) {
		scanf ("%d %d %d %d %d", &x1, &y1, &x2, &y2, &t);
		printf ("%d\n", query ());
	}
	
	return 0;
}