#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e3 + 10;
long long qpow(long long x, long long y, long long MOD) {
  long long a = 1;
  while (y) {
    if (y & 1) a = a * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return a;
}
int n, m, k;
int a[N][N];
int dis[N][N][41], ok[41];
vector<pair<int, int> > v[41];
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
void bfs(int x) {
  queue<pair<int, int> > q;
  for (int i = int(1); i <= int(n); ++i)
    for (int j = int(1); j <= int(m); ++j) {
      if (a[i][j] == x)
        q.push(make_pair(i, j)), dis[i][j][x] = 0;
      else
        dis[i][j][x] = -1;
    }
  memset(ok, 0, sizeof(ok));
  ok[x] = 1;
  while (!q.empty()) {
    pair<int, int> pa = q.front();
    q.pop();
    int r = pa.first, c = pa.second;
    if (!ok[a[r][c]]) {
      for (auto p : v[a[r][c]]) {
        if (dis[p.first][p.second][x] == -1) {
          dis[p.first][p.second][x] = dis[r][c][x] + 1;
          q.push(make_pair(p.first, p.second));
        }
      }
      ok[a[r][c]] = 1;
    }
    for (int i = int(0); i <= int(3); ++i) {
      int nr = r + dr[i], nc = c + dc[i];
      if (nr < 1 || nr > n || nc < 1 || nc > m) continue;
      if (dis[nr][nc][x] != -1) continue;
      dis[nr][nc][x] = dis[r][c][x] + 1;
      q.push(make_pair(nr, nc));
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = int(1); i <= int(n); ++i)
    for (int j = int(1); j <= int(m); ++j) {
      scanf("%d", &a[i][j]);
      v[a[i][j]].push_back(make_pair(i, j));
    }
  for (int i = int(1); i <= int(k); ++i) bfs(i);
  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 = int(1); i <= int(k); ++i)
      ans = min(ans, dis[r1][c1][i] + dis[r2][c2][i] + 1);
    printf("%d\n", ans);
  }
  return 0;
}
