#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
  x = 0;
  int w = 0;
  char g = getchar();
  while (!isdigit(g)) {
    w = (g == '-');
    g = getchar();
  }
  while (isdigit(g)) {
    x = (x << 3) + (x << 1) + (g xor 48);
    g = getchar();
  }
  x = w ? -x : x;
  return;
}
int n, m, k, a[1005][1005], d[1005][1005][43], T;
vector<pair<int, int> > p[45];
queue<pair<int, int> > q;
bool vis[45];
int nxt[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
inline void bfs(int x) {
  memset(vis, 0, sizeof vis);
  int kx, ky;
  for (register int i = 0; i < p[x].size(); i++) {
    kx = p[x][i].first;
    ky = p[x][i].second;
    d[kx][ky][x] = 0;
    q.push(pair<int, int>(kx, ky));
  }
  vis[x] = 1;
  while (!q.empty()) {
    int fx = q.front().first;
    int fy = q.front().second;
    q.pop();
    int mid = a[fx][fy];
    int f = d[fx][fy][x];
    if (!vis[mid]) {
      vis[mid] = 1;
      for (register int i = 0; i < p[mid].size(); i++) {
        kx = p[mid][i].first;
        ky = p[mid][i].second;
        if (d[kx][ky][x] == -1) {
          d[kx][ky][x] = f + 1;
          q.push(pair<int, int>(kx, ky));
        }
      }
    }
    for (register int i = 0; i <= 3; i++) {
      kx = fx + nxt[i][0];
      ky = fy + nxt[i][1];
      if (kx < 1 || ky < 1 || kx > n || ky > m || d[kx][ky][x] != -1) continue;
      d[kx][ky][x] = f + 1;
      q.push(pair<int, int>(kx, ky));
    }
  }
}
int main() {
  read(n);
  read(m);
  read(k);
  memset(d, -1, sizeof d);
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= m; j++) {
      read(a[i][j]);
      p[a[i][j]].push_back(pair<int, int>(i, j));
    }
  for (register int i = 1; i <= k; i++) bfs(i);
  read(T);
  int x1, x2, y1, y2;
  while (T--) {
    read(x1), read(y1);
    read(x2), read(y2);
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (register int i = 1; i <= k; i++) {
      ans = min(ans, d[x1][y1][i] + d[x2][y2][i] + 1);
    }
    cout << ans << "\n";
  }
  return 0;
}
