#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
const int M = 44;
const int mod = 1e9 + 7;
int n, m, k;
int dd[M];
int a[N][N];
int used[N][N];
int d[N][N][M];
vector<pair<int, int> > v[N];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
void solve1() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      v[a[i][j]].push_back({i, j});
    }
  }
  for (int c = 1; c <= k; c++) {
    for (int j = 1; j <= n; j++) {
      for (int h = 1; h <= m; h++) {
        used[j][h] = 0;
      }
    }
    queue<pair<int, int> > q;
    for (int i = 0; i < (int)v[c].size(); i++) {
      auto y = v[c][i];
      q.push(y);
      used[y.first][y.second] = 1;
    }
    for (int j = 1; j <= k; j++) {
      dd[j] = 0;
    }
    dd[c] = 1;
    while (!q.empty()) {
      auto x = q.front();
      q.pop();
      if (!dd[a[x.first][x.second]]) {
        dd[a[x.first][x.second]] = 1;
        for (auto y : v[a[x.first][x.second]]) {
          if (used[y.first][y.second] == 0) {
            d[y.first][y.second][c] = d[x.first][x.second][c] + 1;
            used[y.first][y.second] = 1;
            q.push({y.first, y.second});
          }
        }
      }
      for (int i = 0; i < 4; i++) {
        int nx = dx[i] + x.first;
        int ny = dy[i] + x.second;
        if (nx < 1 || nx > n || ny < 1 || ny > m || used[nx][ny]) continue;
        used[nx][ny] = 1;
        d[nx][ny][c] = d[x.first][x.second][c] + 1;
        q.push({nx, ny});
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int i1, j1, i2, j2;
    cin >> i1 >> j1 >> i2 >> j2;
    int ans = abs(i2 - i1) + abs(j2 - j1);
    for (int j = 1; j <= k; j++) {
      ans = min(ans, d[i1][j1][j] + 1 + d[i2][j2][j]);
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int cghf = 1;
  while (cghf--) {
    solve1();
  }
}
