#include <bits/stdc++.h>
using namespace std;
const int maxn = 1003, maxm = 43, INF = 30000, dx[4] = {1, 0, -1, 0},
          dy[4] = {0, 1, 0, -1};
int a[maxn][maxn], n, m, k, Q;
short dis[maxm][maxn][maxn];
bool vis[maxm];
struct T {
  int x, y;
  T() {}
  T(int _x, int _y) : x(_x), y(_y) {}
};
vector<T> v[maxm];
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", a[i] + j), v[a[i][j]].emplace_back(i, j);
  for (int col = 1; col <= k; col++) {
    queue<T> q;
    for (int i = 1; i <= k; i++) vis[i] = 0;
    vis[col] = 1;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        dis[col][i][j] = INF;
        if (a[i][j] == col) dis[col][i][j] = 0, q.emplace(i, j);
      }
    while (!q.empty()) {
      T u = q.front();
      q.pop();
      if (!vis[a[u.x][u.y]]) {
        vis[a[u.x][u.y]] = 1;
        for (const T &i : v[a[u.x][u.y]]) {
          if (dis[col][i.x][i.y] == INF) {
            dis[col][i.x][i.y] = dis[col][u.x][u.y] + 1;
            q.emplace(i.x, i.y);
          }
        }
      }
      for (int i = 0; i < 4; i++) {
        int x = u.x + dx[i], y = u.y + dy[i];
        if (x >= 1 && x <= n && y >= 1 && y <= m && dis[col][x][y] == INF) {
          dis[col][x][y] = dis[col][u.x][u.y] + 1;
          q.emplace(x, y);
        }
      }
    }
  }
  scanf("%d", &Q);
  while (Q--) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (int i = 1; i <= k; i++)
      ans = min(ans, dis[i][x1][y1] + dis[i][x2][y2] + 1);
    printf("%d\n", ans);
  }
  return 0;
}
