#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = 45;
struct Node {
  int x, y;
  Node(int x, int y) : x(x), y(y) {}
};
int n, m, k, q, g[N][N], d[N][N][M];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
bool vis[M];
vector<Node> c[N];
void bfs(int k) {
  queue<Node> q;
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < c[k].size(); i++) {
    int x = c[k][i].x, y = c[k][i].y;
    q.push(Node(x, y));
    d[x][y][k] = 0;
  }
  vis[k] = true;
  while (!q.empty()) {
    Node t = q.front();
    q.pop();
    int dd = d[t.x][t.y][k];
    int tc = g[t.x][t.y];
    if (!vis[tc]) {
      vis[tc] = true;
      for (int i = 0; i < c[tc].size(); i++) {
        int x = c[tc][i].x, y = c[tc][i].y;
        if (d[x][y][k] > dd + 1) {
          d[x][y][k] = dd + 1;
          q.push(Node(x, y));
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      int x = t.x + dx[i];
      int y = t.y + dy[i];
      if (x > 0 && y > 0 && x <= n && y <= m && d[x][y][k] > dd + 1) {
        d[x][y][k] = dd + 1;
        q.push(Node(x, y));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &g[i][j]);
      c[g[i][j]].push_back(Node(i, j));
    }
  }
  memset(d, 0x3f, sizeof(d));
  for (int i = 1; i <= k; i++) bfs(i);
  scanf("%d", &q);
  while (q--) {
    int x1, x2, y1, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int ans = abs(x2 - x1) + abs(y2 - y1);
    for (int i = 1; i <= k; i++)
      ans = min(ans, d[x1][y1][i] + d[x2][y2][i] + 1);
    printf("%d\n", ans);
  }
  return 0;
}
