#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
inline void bugp(const pair<T, V> &x) {
  cerr << '{' << x.first << ", " << x.second << "}\n";
}
template <typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {
  cerr << '{' << x.first << ", {" << x.second.first << ", " << x.second.second
       << "}}\n";
}
const int N = 1001, M = 1001, K = 44;
int n, m, k, C[N][M], data[N][M][K], dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
bool visit[N][M], done[K];
vector<pair<int, int> > color[K];
inline bool valid(const int &x, const int &y) {
  return x >= 1 && x <= n && y >= 1 && y <= m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  fill(&data[0][0][0], &data[0][0][0] + sizeof(data) / sizeof(int), 1e9);
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1, _n = (n); i <= _n; ++i)
    for (int j = 1, _n = (m); j <= _n; ++j) {
      scanf("%d", &C[i][j]);
      color[C[i][j]].push_back({i, j});
    }
  int a, b, x, y, col, q, ans;
  for (int c = 1, _n = (k); c <= _n; ++c) {
    queue<pair<int, int> > q;
    fill(&visit[0][0], &visit[0][0] + sizeof(visit), false);
    for (int i = 0, _n = (color[c].size()); i < _n; ++i) {
      x = color[c][i].first;
      y = color[c][i].second;
      data[x][y][c] = 0;
      visit[x][y] = true;
      q.push(color[c][i]);
    }
    fill(done, done + K, false);
    done[c] = true;
    while (q.size()) {
      x = q.front().first;
      y = q.front().second;
      q.pop();
      col = C[x][y];
      if (!done[col]) {
        done[col] = true;
        for (int i = 0, _n = (color[col].size()); i < _n; ++i) {
          a = color[col][i].first;
          b = color[col][i].second;
          if (data[a][b][c] > data[x][y][c] + 1) {
            data[a][b][c] = data[x][y][c] + 1;
            if (!visit[a][b]) {
              visit[a][b] = true;
              q.push({a, b});
            }
          }
        }
      }
      for (int t = 0, _n = (4); t < _n; ++t) {
        a = x + dx[t];
        b = y + dy[t];
        if (valid(a, b) && data[a][b][c] > data[x][y][c] + 1) {
          data[a][b][c] = data[x][y][c] + 1;
          if (!visit[a][b]) {
            visit[a][b] = true;
            q.push({a, b});
          }
        }
      }
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d %d", &a, &b, &x, &y);
    ans = abs(a - x) + abs(b - y);
    for (int c = 1, _n = (k); c <= _n; ++c)
      ans = min(ans, data[a][b][c] + data[x][y][c] + 1);
    cout << ans << '\n';
  }
  return 0;
}
