#include <fstream>
#include <vector>

using namespace std;

const char iname[] = "robotel.in";
const char oname[] = "robotel.out";
const int maxn = 105;
const int mod = 666013;

ifstream f(iname);
ofstream g(oname);

int bad[maxn][maxn], mat[17][maxn][maxn];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

void mul(int a[][maxn],int b[][maxn], int c[][maxn], int n, int m, int p) {
	for (int k = 0; k < p; ++k)
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				c[i][k] = (c[i][k] + static_cast<long long>(a[i][j] * b[k][j])) % mod;
}

int main() {
	int N, M, K;
	f >> N >> M >> K;

	for (int i = 0; i <= N; ++i)
		bad[i][0] = bad[i][M + 1] = 1;
	
	for (int i = 0; i <= M; ++i)
		bad[0][i] = bad[N + 1][i] = 1;

	for (int i = 0; i < K; ++i) {
		int x, y;
		f >> x >> y;
		bad[x][y] = 1;
	}

	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= M; ++j)
			for (int k = 0; k < 4; ++k)
				if (bad[i][j] == 0 && bad[i + dx[k]][j + dy[k]] == 0)
					mat[0][(i - 1) * M + j - 1][(i + dx[k] - 1) * M + j + dy[k] - 1] = 1;
	
	for (int i = 1; i <= 16; ++i)
		mul(mat[i - 1], mat[i - 1], mat[i], N * M, N * M, N * M);
	
	
	int P; f >> P;
	int nodes = N * M;
	
	while (P--) {
		int x1, y1, x2, y2, T, nod1, nod2;
		f >> x1 >> y1 >> x2 >> y2 >> T;
		nod1 = (x1 - 1) * M + y1 - 1;
		nod2 = (x2 - 1) * M + y2 - 1;

		vector<int> past(nodes, 0), present(nodes, 0);
		present[nod1] = 1;
		for (int step = 0; step <= 16; ++step)
			if ((1 << step) & T) {
				swap(past, present);
				for (int i = 0; i < nodes; ++i)
					for (int j = 0; j < nodes; ++j)
						present[j] = (present[j] + static_cast<long long>(past[i]) * mat[step][i][j]) % mod;
			}
		g << present[nod2] << "\n";
	}

}

