#include <bits/stdc++.h>
using namespace std;
void initial() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
mt19937_64 rnd(time(0));
const int maxn = 1010;
const int maxc = 45;
int a[maxn][maxn];
int dist[maxn][maxn][maxc];
vector<pair<int, int>> dx = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int n, m;
bool ok(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
bool used[maxc];
bool kk[maxn][maxn];
vector<pair<int, int>> was[maxc];
signed main() {
  initial();
  cin >> n >> m;
  int k;
  cin >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      was[a[i][j]].push_back({i, j});
    }
  memset(dist, -1, sizeof(dist));
  for (int c = 1; c < maxc; c++) {
    queue<pair<int, int>> q;
    for (auto [i, j] : was[c]) {
      q.push({i, j});
      dist[i][j][c] = 0;
    }
    memset(used, false, sizeof(used));
    memset(kk, false, sizeof(kk));
    while (!q.empty()) {
      auto [x, y] = q.front();
      q.pop();
      if (kk[x][y]) continue;
      kk[x][y] = true;
      if (!used[a[x][y]]) {
        for (auto [i, j] : was[a[x][y]]) {
          if (dist[i][j][c] == -1 || dist[i][j][c] > dist[x][y][c] + 1) {
            dist[i][j][c] = dist[x][y][c] + 1;
            q.push({i, j});
          }
        }
        used[a[x][y]] = true;
      }
      for (auto [xx, yy] : dx) {
        xx += x;
        yy += y;
        if (!ok(xx, yy)) continue;
        if (dist[xx][yy][c] == -1 || dist[xx][yy][c] > dist[x][y][c] + 1) {
          dist[xx][yy][c] = dist[x][y][c] + 1;
          q.push({xx, yy});
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y, i, j;
    cin >> x >> y >> i >> j;
    x--;
    y--;
    i--;
    j--;
    int ans = abs(x - i) + abs(y - j);
    for (int c = 1; c <= maxc; c++) {
      if (dist[x][y][c] == -1 || dist[i][j][c] == -1) continue;
      ans = min(ans, int(dist[x][y][c] + dist[i][j][c] + 1));
    }
    cout << ans << '\n';
  }
  return 0;
}
