#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int INF = 1e9 + 10;
int n, m, k, G[maxn][maxn], dis[maxn][maxn][50];
bool vis[maxn][maxn], visc[50];
struct Node {
  int x, y;
  Node(int x = 0, int y = 0) : x(x), y(y) {}
};
vector<Node> color[50];
void BFS(int c) {
  memset(visc, 0, sizeof(visc));
  memset(vis, 0, sizeof(vis));
  queue<Node> q;
  for (int i = 0; i < color[c].size(); i++) {
    int x = color[c][i].x, y = color[c][i].y;
    q.push(Node(x, y));
    dis[x][y][c] = 0;
    vis[x][y] = 1;
  }
  visc[c] = 1;
  while (!q.empty()) {
    Node u = q.front();
    q.pop();
    int ux = u.x, uy = u.y;
    int uc = G[ux][uy];
    if (!visc[uc]) {
      visc[uc] = 1;
      for (int i = 0; i < color[uc].size(); i++) {
        Node v = color[uc][i];
        int vx = v.x, vy = v.y;
        if (!vis[vx][vy]) {
          vis[vx][vy] = 1;
          dis[vx][vy][c] = dis[ux][uy][c] + 1;
          q.push(Node(vx, vy));
        }
      }
    }
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++)
        if (abs(i + j) == 1 and i + ux <= n and i + ux >= 1 and j + uy <= m and
            j + uy >= 1) {
          int vx = i + ux, vy = j + uy;
          if (!vis[vx][vy]) {
            vis[vx][vy] = 1;
            dis[vx][vy][c] = dis[ux][uy][c] + 1;
            q.push(Node(vx, vy));
          }
        }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      G[i][j] = x;
      color[x].push_back(Node(i, j));
    }
  for (int i = 1; i <= k; i++) BFS(i);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (int j = 1; j <= k; j++)
      ans = min(ans, dis[x1][y1][j] + dis[x2][y2][j] + 1);
    printf("%d\n", ans);
  }
}
