#include <bits/stdc++.h>
using namespace std;
int dis[1010][1010][42];
int mp[1010][1010];
int cvis[42];
vector<pair<int, int> > col[42];
int dirx[4] = {1, -1, 0, 0};
int diry[4] = {0, 0, 1, -1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mp[i][j];
      col[mp[i][j]].push_back({i, j});
    }
  }
  queue<pair<pair<int, int>, int> > q;
  for (int i = 1; i <= k; i++) {
    for (int i = 1; i <= k; i++) cvis[i] = 0;
    for (auto &it : col[i]) {
      dis[it.first][it.second][i] = 1;
      q.push({it, 1});
    }
    cvis[i] = 1;
    while (!q.empty()) {
      auto tmp = q.front();
      q.pop();
      int x = tmp.first.first;
      int y = tmp.first.second;
      int d = tmp.second;
      for (int o = 0; o < 4; o++) {
        int nowx = x + dirx[o];
        int nowy = y + diry[o];
        if (nowx >= 1 && nowx <= n && nowy >= 1 && nowy <= m &&
            !dis[nowx][nowy][i]) {
          dis[nowx][nowy][i] = d + 1;
          q.push({{nowx, nowy}, d + 1});
        }
      }
      if (!cvis[mp[x][y]]) {
        cvis[mp[x][y]] = 1;
        for (auto &it : col[mp[x][y]]) {
          if (!dis[it.first][it.second][i]) {
            dis[it.first][it.second][i] = d + 1;
            q.push({{it.first, it.second}, d + 1});
          }
        }
      }
    }
  }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = abs(a - c) + abs(b - d);
    for (int i = 1; i <= k; i++) {
      ans = min(ans, dis[a][b][i] + dis[c][d][i] - 1);
    }
    cout << ans << endl;
  }
}
