#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 255;
int pic[maxn][maxn], f[maxn][maxn], g[maxn][maxn];
int main()
{
	int n, b, k;
	while (~scanf("%d%d%d", &n, &b, &k)) {
		memset(f, 0, sizeof f);
		memset(g, 0x3f, sizeof g);
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				scanf("%d", &pic[i][j]);
		int r = n - b + 1;
		for (int i = 1; i <= r; ++i) {
			for (int j = 1; j <= r; ++j) {
				int i_r = i + b - 1, j_r = j + b - 1;
				for (int ii = i; ii <= i_r; ++ii) {
					for (int jj = j; jj <= j_r; ++jj) {
						f[i][j] = max(f[i][j], pic[ii][jj]);
						g[i][j] = min(g[i][j], pic[i][j]);
					}
				}
			}
		}
		while (k--) {
			int x, y;
			scanf("%d%d", &x, &y);
			printf("%d\n", f[x][y] - g[x][y]);
		}
	}

	return 0;
}
