#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Os")
const int maxn = 1e3 + 7;
const int maxk = 40;
const int maxq = 1e5 + 10;
const int inf = 1e9 + 7;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int ans[maxq];
int n, m, k, q;
queue<int> BFS[2];
int grd[maxn][maxn];
bitset<maxn * maxn> Mark;
vector<int> pashmak[maxk];
int dis[maxk][maxn * maxn];
inline void in();
inline void solve();
inline void make_graph();
inline void make_colorVerts();
inline void tofmof();
inline void bfs(int, int);
inline void out();
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  in();
  solve();
  out();
}
inline void in() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grd[i + 1][j + 1];
      grd[i + 1][j + 1]--;
      pashmak[grd[i + 1][j + 1]].push_back(i * m + j);
    }
  }
  cin >> q;
}
inline void solve() {
  tofmof();
  for (int i = 0; i < q; i++) {
    int x, y, X, Y;
    cin >> x >> y >> X >> Y;
    ans[i] = abs(x - X) + abs(y - Y);
    ans[i] *= 2;
    for (int c = 0; c < k; c++)
      ans[i] =
          min(ans[i], dis[c][x * m - m + y - 1] + dis[c][X * m - m + Y - 1]);
    ans[i] /= 2;
  }
}
inline void tofmof() {
  for (int c = 0; c < k; c++) bfs(n * m + c, c);
}
inline void bfs(int u, int id) {
  BFS[0].push(u);
  for (int i = 0; i < n * m + k; i++) Mark[i] = 0;
  Mark[u] = 1;
  while (BFS[0].size() + BFS[1].size()) {
    int u;
    if (BFS[0].size()) {
      u = BFS[0].front();
      BFS[0].pop();
    } else {
      u = BFS[1].front();
      BFS[1].pop();
    }
    if (u >= n * m) {
      for (auto v : pashmak[u - n * m]) {
        if (!Mark[v]) {
          Mark[v] = 1;
          dis[id][v] = dis[id][u] + 1;
          BFS[1].push(v);
        }
      }
    } else {
      int x = u / m + 1;
      int y = u % m + 1;
      if (!Mark[grd[x][y] + n * m]) {
        Mark[grd[x][y] + n * m] = 1;
        dis[id][grd[x][y] + n * m] = dis[id][u] + 1;
        BFS[0].push(grd[x][y] + n * m);
      }
      for (int i = 0; i < 4; i++) {
        int X = x + dx[i];
        int Y = y + dy[i];
        int v = X * m - m + Y - 1;
        if (X && Y && X <= n && Y <= m && !Mark[v]) {
          Mark[v] = 1;
          dis[id][v] = dis[id][u] + 2;
          BFS[1].push(v);
        }
      }
    }
  }
}
inline void out() {
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
}
