#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, k, gr[1050][1050], dis[1050][1050][44], xx[] = {1, -1, 0, 0},
                                                  yy[] = {0, 0, 1, -1}, did[44];
vector<pair<int, int> > nod[44];
void bfs(int cal) {
  queue<pair<int, int> > qr;
  memset(did, 0, sizeof did);
  for (int i = 0; i < nod[cal].size(); i++) {
    pair<int, int> z = nod[cal][i];
    int x = z.first, y = z.second;
    qr.push({x, y});
    dis[x][y][cal] = 0;
  }
  while (qr.size()) {
    pair<int, int> z = qr.front();
    int x = z.first, y = z.second;
    qr.pop();
    for (int i = 0; i < 4; i++) {
      int tx = x + xx[i], ty = y + yy[i];
      if (0 <= tx && tx < n && 0 <= ty && ty < m &&
          dis[tx][ty][cal] > dis[x][y][cal] + 1) {
        dis[tx][ty][cal] = dis[x][y][cal] + 1;
        qr.push({tx, ty});
      }
    }
    if (did[gr[x][y]] == 0) {
      did[gr[x][y]] = 1;
      for (int i = 0; i < nod[gr[x][y]].size(); i++) {
        pair<int, int> z = nod[gr[x][y]][i];
        int tx = z.first, ty = z.second;
        if (dis[tx][ty][cal] > dis[x][y][cal] + 1) {
          dis[tx][ty][cal] = dis[x][y][cal] + 1;
          qr.push({tx, ty});
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int z = 1; z <= k; z++) dis[i][j][z] = 1e9;
      scanf("%d", &gr[i][j]);
      nod[gr[i][j]].push_back({i, j});
    }
  }
  for (int i = 1; i <= k; i++) bfs(i);
  int T;
  scanf("%d", &T);
  while (T--) {
    int ax, ay, bx, by;
    scanf("%d", &ax);
    scanf("%d", &ay);
    scanf("%d", &bx);
    scanf("%d", &by);
    ax--, ay--, bx--, by--;
    int ans = abs(ax - bx) + abs(ay - by);
    for (int i = 1; i <= k; i++)
      ans = min(ans, dis[ax][ay][i] + dis[bx][by][i] + 1);
    printf("%d\n", ans);
  }
}
