#include <bits/stdc++.h>
using namespace std;
bool debug = true;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> ptt) {
  os << ptt.first << "," << ptt.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vt) {
  os << "{";
  for (int i = 0; i < vt.size(); i++) {
    os << vt[i] << " ";
  }
  os << "}";
  return os;
}
int n, m, k;
int col[1005][1005];
int dis[45][1005][1005];
vector<pair<int, int> > cs[45];
bool done[45];
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
void bfs(int c) {
  memset(done, false, sizeof(done));
  memset(dis[c], -1, sizeof(dis[c]));
  queue<pair<int, int> > q;
  for (pair<int, int> x : cs[c]) {
    q.push(x);
    dis[c][x.first][x.second] = 0;
  }
  while (!q.empty()) {
    pair<int, int> last = q.front();
    q.pop();
    if (!done[col[last.first][last.second]]) {
      done[col[last.first][last.second]] = true;
      for (pair<int, int> x : cs[col[last.first][last.second]]) {
        if (dis[c][x.first][x.second] == -1) {
          dis[c][x.first][x.second] = dis[c][last.first][last.second] + 1;
          q.push(x);
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      int nx = dx[i] + last.first, ny = dy[i] + last.second;
      if (nx >= 0 && nx < n && ny >= 0 && ny < m && dis[c][nx][ny] == -1) {
        dis[c][nx][ny] = dis[c][last.first][last.second] + 1;
        q.push(make_pair(nx, ny));
      }
    }
  }
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> col[i][j];
      col[i][j]--;
      cs[col[i][j]].push_back(make_pair(i, j));
    }
  }
  for (int i = 0; i < k; i++) {
    bfs(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int ans = abs(c - a) + abs(d - b);
    for (int j = 0; j < k; j++) {
      ans = min(ans, dis[j][a][b] + dis[j][c][d] + 1);
    }
    cout << ans << endl;
  }
  return 0;
}
