#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, M = 1e3 + 5, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int rn, cm, colk, col[N][M], dis[45][N][M];
bool vis[N][M], visCol[45];
struct Node;
vector<Node> colSet[45];
struct Node {
  int x, y;
  Node(int _x, int _y) : x(_x), y(_y) {}
  Node() : x(0), y(0) {}
};
void Bfs(int c) {
  memset(vis, 0, sizeof(vis));
  memset(visCol, 0, sizeof(visCol));
  queue<Node> Q;
  while (!Q.empty()) Q.pop();
  for (int i = 0; i < colSet[c].size(); ++i) {
    Q.push(colSet[c][i]), dis[c][colSet[c][i].x][colSet[c][i].y] = 0;
    vis[colSet[c][i].x][colSet[c][i].y] = 0;
  }
  visCol[c] = 1;
  while (!Q.empty()) {
    Node cur = Q.front();
    Q.pop();
    if (!visCol[col[cur.x][cur.y]]) {
      visCol[col[cur.x][cur.y]] = 1;
      for (int i = 0; i < colSet[col[cur.x][cur.y]].size(); ++i) {
        Node to = colSet[col[cur.x][cur.y]][i];
        if (vis[to.x][to.y]) continue;
        vis[to.x][to.y] = 1;
        dis[c][to.x][to.y] = min(dis[c][to.x][to.y], dis[c][cur.x][cur.y] + 1);
        Q.push(to);
      }
    }
    for (int i = 0; i < 4; ++i) {
      int nx = cur.x + dx[i], ny = cur.y + dy[i];
      if (nx < 1 || nx > rn || ny < 1 || ny > cm) continue;
      if (vis[nx][ny]) continue;
      vis[nx][ny] = 1;
      dis[c][nx][ny] = min(dis[c][nx][ny], dis[c][cur.x][cur.y] + 1);
      Q.push(Node(nx, ny));
    }
  }
}
int abs(int fir, int sec) {
  if (fir - sec > 0)
    return fir - sec;
  else
    return sec - fir;
}
int main() {
  memset(dis, 0x3f, sizeof(dis));
  scanf("%d%d%d", &rn, &cm, &colk);
  for (int i = 1; i <= rn; ++i)
    for (int j = 1; j <= cm; ++j)
      scanf("%d", &col[i][j]), colSet[col[i][j]].push_back(Node(i, j));
  for (int i = 1; i <= colk; ++i) Bfs(i);
  int nbQ;
  scanf("%d", &nbQ);
  while (nbQ--) {
    int r1, c1, r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    int ans = abs(r2, r1) + abs(c2, c1);
    for (int cl = 1; cl <= colk; ++cl) {
      ans = min(ans, dis[cl][r1][c1] + dis[cl][r2][c2] + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
