#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005, maxk = 45;
int n, m, k, q, dis[maxk][maxn][maxn], a[maxn][maxn],
    mo[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
bool vis[maxn][maxn], done[maxk];
vector<pair<int, int> > v[maxk];
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= m; k++) {
      scanf(" %d", &a[i][k]);
      v[a[i][k]].push_back(make_pair(i, k));
    }
  }
  for (int c = 1; c <= k; c++) {
    memset(vis, 0, sizeof vis);
    memset(done, 0, sizeof done);
    queue<pair<int, int> > q;
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= m; k++)
        if (a[i][k] == c) vis[i][k] = true, q.push(make_pair(i, k));
    done[c] = true;
    while (q.size()) {
      int x = q.front().first, y = q.front().second;
      q.pop();
      if (!done[a[x][y]]) {
        done[a[x][y]] = true;
        for (pair<int, int> ck : v[a[x][y]]) {
          if (vis[ck.first][ck.second]) continue;
          vis[ck.first][ck.second] = true;
          dis[c][ck.first][ck.second] = dis[c][x][y] + 1;
          q.push(ck);
        }
      }
      for (int i = 0; i < 4; i++) {
        int nx = x + mo[i][0], ny = y + mo[i][1];
        if (nx >= 1 && ny >= 1 && nx <= n && ny <= m && !vis[nx][ny]) {
          vis[nx][ny] = true;
          dis[c][nx][ny] = dis[c][x][y] + 1;
          q.push(make_pair(nx, ny));
        }
      }
    }
  }
  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 c = 1; c <= k; c++)
      ans = min(ans, dis[c][r1][c1] + dis[c][r2][c2] + 1);
    printf("%d\n", ans);
  }
}
