#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, k, q, arr[1005][1005], vis[41][41], dist[41][1005][1005];
vector<pii> byColor[45];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool valid(int first, int second) {
  return first >= 1 && first <= n && second >= 1 && second <= m;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> arr[i][j];
      byColor[arr[i][j]].push_back({i, j});
    }
  }
  for (int color = 1; color <= k; color++) {
    queue<pii> Q;
    vis[color][color] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        dist[color][i][j] = mod;
      }
    }
    for (pii p : byColor[color]) {
      Q.push(p);
      dist[color][p.first][p.second] = 0;
    }
    while ((int)Q.size()) {
      int first = Q.front().first, second = Q.front().second;
      int d = dist[color][first][second];
      Q.pop();
      if (!vis[color][arr[first][second]]) {
        vis[color][arr[first][second]] = 1;
        for (pii p : byColor[arr[first][second]]) {
          if (dist[color][p.first][p.second] > d + 1) {
            dist[color][p.first][p.second] = d + 1;
            Q.push(p);
          }
        }
      }
      for (int dir = 0; dir < 4; dir++) {
        int nx = first + dx[dir], ny = second + dy[dir];
        if (!valid(nx, ny)) {
          continue;
        }
        if (dist[color][nx][ny] > d + 1) {
          dist[color][nx][ny] = d + 1;
          Q.push({nx, ny});
        }
      }
    }
  }
  cin >> q;
  while (q--) {
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (int i = 1; i <= k; i++) {
      ans = min(ans, dist[i][x1][y1] + dist[i][x2][y2] + 1);
    }
    cout << ans << "\n";
  }
  return 0;
}
