#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 1e3 + 7;
const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m, k, dist[44][MAXN][MAXN], A[MAXN][MAXN];
bool viscol[44];
vector<pair<int, int>> vec[44];
void solver(int c) {
  memset(viscol, 0, sizeof(viscol));
  viscol[c] = true;
  memset(dist[c], 0, sizeof(dist[c]));
  queue<pair<pair<int, int>, int>> que;
  for (auto coor : vec[c]) {
    dist[c][coor.first][coor.second] = 1;
    que.push(make_pair(coor, 1));
  }
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    auto coor = p.first;
    int step = p.second;
    if (!viscol[A[coor.first][coor.second]]) {
      viscol[A[coor.first][coor.second]] = true;
      for (auto pp : vec[A[coor.first][coor.second]]) {
        if (!dist[c][pp.first][pp.second]) {
          dist[c][pp.first][pp.second] = step + 1;
          que.push(make_pair(pp, step + 1));
        }
      }
    }
    for (int d = 0; d < 4; d++) {
      int nx = coor.first + dir[d][0];
      int ny = coor.second + dir[d][1];
      if (nx < 1 || ny < 1 || nx > n || ny > m || dist[c][nx][ny]) continue;
      dist[c][nx][ny] = step + 1;
      que.push(make_pair(make_pair(nx, ny), step + 1));
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &A[i][j]);
      vec[A[i][j]].emplace_back(make_pair(i, j));
    }
  for (int c = 1; c <= k; c++) solver(c);
  int q;
  for (scanf("%d", &q); q; q--) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    int res = abs(x1 - x2) + abs(y1 - y2);
    for (int c = 1; c <= k; c++)
      res = min(res, dist[c][x1][y1] + dist[c][x2][y2] - 1);
    printf("%d\n", res);
  }
  return 0;
}
