#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 1001;
const int M = 41;
int power(int b, long long exp) {
  int res = 1;
  while (exp > 0) {
    if (exp % 2) {
      res = 1LL * res * b % mod;
    }
    b = 1LL * b * b % mod;
    exp /= 2;
  }
  return res;
}
int dis[M][N][N], a[N][N];
int main() {
  int test = 1;
  while (test--) {
    int n, m, k, q;
    vector<pair<int, int> > col[M];
    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]);
        col[a[i][j]].push_back({i, j});
      }
    }
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= n; j++) {
        for (int l = 1; l <= m; l++) {
          dis[i][j][l] = 1e9;
        }
      }
    }
    for (int i = 1; i <= k; i++) {
      queue<pair<int, int> > dq;
      vector<int> vis(k + 1, 0);
      for (auto p : col[i]) {
        dis[i][p.first][p.second] = 0;
        dq.push(p);
      }
      vis[i] = 1;
      while (!dq.empty()) {
        auto p = dq.front();
        dq.pop();
        int x = p.first, y = p.second;
        if (!vis[a[x][y]]) {
          for (auto p1 : col[a[x][y]]) {
            if (dis[i][p1.first][p1.second] > dis[i][x][y] + 1) {
              dis[i][p1.first][p1.second] = dis[i][x][y] + 1;
              dq.push(p1);
            }
          }
          vis[a[x][y]] = 1;
        }
        if (x - 1 > 0 && dis[i][x - 1][y] > dis[i][x][y] + 1) {
          dis[i][x - 1][y] = dis[i][x][y] + 1;
          dq.push({x - 1, y});
        }
        if (x + 1 <= n && dis[i][x + 1][y] > dis[i][x][y] + 1) {
          dis[i][x + 1][y] = dis[i][x][y] + 1;
          dq.push({x + 1, y});
        }
        if (y - 1 > 0 && dis[i][x][y - 1] > dis[i][x][y] + 1) {
          dis[i][x][y - 1] = dis[i][x][y] + 1;
          dq.push({x, y - 1});
        }
        if (y + 1 <= m && dis[i][x][y + 1] > dis[i][x][y] + 1) {
          dis[i][x][y + 1] = dis[i][x][y] + 1;
          dq.push({x, y + 1});
        }
      }
    }
    scanf("%d", &q);
    while (q--) {
      int r1, c1, r2, c2;
      scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
      int ans = abs(r1 - r2) + abs(c1 - c2);
      for (int i = 1; i <= k; i++) {
        ans = min(ans, 1 + dis[i][r1][c1] + dis[i][r2][c2]);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
