#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5, maxk = 50;
struct node {
  int x, y;
};
vector<node> G[50];
int col[maxn][maxn];
int n, m, k, q, ans;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int dis[maxn][maxn][maxk];
bool vis[maxk];
void bfs(int c) {
  int i;
  int x, y, u, v, w;
  queue<node> q;
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < G[c].size(); i++) {
    q.push(G[c][i]);
    dis[G[c][i].x][G[c][i].y][c] = 0;
  }
  vis[c] = 1;
  while (!q.empty()) {
    x = q.front().x;
    y = q.front().y;
    w = col[x][y];
    q.pop();
    if (!vis[w]) {
      for (i = 0; i < G[w].size(); i++) {
        u = G[w][i].x;
        v = G[w][i].y;
        if (dis[u][v][c] != -1) continue;
        dis[u][v][c] = dis[x][y][c] + 1;
        q.push((node){u, v});
      }
      vis[w] = 1;
    }
    for (i = 0; i < 4; i++) {
      u = x + dx[i];
      v = y + dy[i];
      if (u > n || v > m || u < 1 || v < 1) continue;
      if (dis[u][v][c] != -1) continue;
      dis[u][v][c] = dis[x][y][c] + 1;
      q.push((node){u, v});
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int i, j;
  int sx, sy, ex, ey;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      scanf("%d", &col[i][j]);
      G[col[i][j]].push_back((node){i, j});
    }
  scanf("%d", &q);
  memset(dis, -1, sizeof(dis));
  for (i = 1; i <= k; i++) bfs(i);
  for (i = 1; i <= q; i++) {
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    ans = abs(sx - ex) + abs(sy - ey);
    for (j = 1; j <= k; j++)
      ans = min(ans, dis[sx][sy][j] + dis[ex][ey][j] + 1);
    printf("%d\n", ans);
  }
  return 0;
}
