#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int M = 1e6 + 100;
const int K = 41;
int rd() {
  int f = 0, s = 1;
  char w;
  for (w = getchar(); w < '0' || w > '9'; w = getchar())
    if (w == '-') s = -1;
  for (; '0' <= w && w <= '9'; w = getchar()) f = f * 10 + w - '0';
  return f * s;
}
struct edge {
  int to, co;
};
vector<edge> e[M];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int n, m, k, Q;
int col[N][N], cnt = 0, colo[K];
int ans[M], r1[M], r2[M], c1[M], c2[M];
int dis[M];
int vis[M];
void adde(int u, int v, int w) { e[u].push_back(edge{v, w}); }
void rebg(int n, int m) {
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      for (int k = 0; k <= 3; k++) {
        int nx = x + dx[k], ny = y + dy[k];
        if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
        if (col[x][y] == col[nx][ny]) continue;
        adde((x - 1) * m + y, (nx - 1) * m + ny, 1);
      }
    }
  }
  cnt = n * m;
  for (int i = 1; i <= k; i++) colo[i] = ++cnt;
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      adde(colo[col[x][y]], (x - 1) * m + y, 0);
      adde((x - 1) * m + y, colo[col[x][y]], 1);
    }
  }
  return;
}
void dijkstra(int c, int s, int n) {
  static queue<int> q[2];
  int now = 0;
  for (int i = 1; i <= n; i++) dis[i] = n * m + 1, vis[i] = 0;
  dis[s] = 0;
  q[now].push(s);
  while (!q[now].empty() || !q[now ^ 1].empty()) {
    int u;
    if (q[now].empty()) now ^= 1;
    u = q[now].front();
    q[now].pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = 0; i < (int)e[u].size(); i++) {
      int v = e[u][i].to;
      int w = e[u][i].co;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        if (w == 0)
          q[now].push(v);
        else
          q[now ^ 1].push(v);
      }
    }
  }
  for (int i = 1; i <= Q; i++)
    ans[i] = min(ans[i], dis[(r1[i] - 1) * m + c1[i]] +
                             dis[(r2[i] - 1) * m + c2[i]] + 1);
  return;
}
int main() {
  n = rd(), m = rd(), k = rd();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) col[i][j] = rd();
  Q = rd();
  for (int i = 1; i <= Q; i++) {
    r1[i] = rd(), c1[i] = rd(), r2[i] = rd(), c2[i] = rd();
    ans[i] = abs(r1[i] - r2[i]) + abs(c1[i] - c2[i]);
  }
  rebg(n, m);
  for (int i = 1; i <= k; i++) dijkstra(i, colo[i], cnt);
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
