#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int a[1002][1002];
int dp[1002][1002][42];
vector<pair<int, int> > co[42];
bool vis[42];
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m, k;
  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]);
      co[a[i][j]].emplace_back(pair<int, int>(i, j));
    }
  }
  for (int c = 1; c <= k; c++) {
    memset(vis, 0, sizeof(vis));
    vis[c] = 1;
    queue<pair<int, int> > q;
    for (int i = 0; i < co[c].size(); i++) {
      int y = co[c][i].first, x = co[c][i].second;
      q.push(pair<int, int>(y, x));
      dp[y][x][c] = 0;
    }
    while (!q.empty()) {
      int y = q.front().first, x = q.front().second;
      int vc = a[y][x];
      q.pop();
      if (!vis[vc]) {
        vis[vc] = 1;
        for (int i = 0; i < co[vc].size(); i++) {
          int vy = co[vc][i].first, vx = co[vc][i].second;
          if (dp[vy][vx][c] == -1) {
            dp[vy][vx][c] = dp[y][x][c] + 1;
            q.push(pair<int, int>(vy, vx));
          }
        }
      }
      for (int i = 0; i < 4; i++) {
        int vy = y + dir[i][0];
        int vx = x + dir[i][1];
        if (1 <= vy && vy <= n && 1 <= vx && vx <= m) {
          if (dp[vy][vx][c] == -1) {
            dp[vy][vx][c] = dp[y][x][c] + 1;
            q.push(pair<int, int>(vy, vx));
          }
        }
      }
    }
  }
  int q;
  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, dp[r1][c1][i] + dp[r2][c2][i] + 1);
    }
    printf("%d\n", ans);
  }
}
