#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
int a[1001][1001];
int d[41][1001][1001];
bool ok[1001][1001];
vector<pair<int, int> > col[41];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
void cal(int c) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      d[c][i][j] = 1e9;
      ok[i][j] = false;
    }
  queue<pair<int, int> > CurrList;
  for (int i = 0; i < col[c].size(); i++) {
    int x = col[c][i].first;
    int y = col[c][i].second;
    d[c][x][y] = 0;
    ok[x][y] = true;
    CurrList.push(pair<int, int>(x, y));
  }
  while (!CurrList.empty()) {
    int x = CurrList.front().first;
    int y = CurrList.front().second;
    CurrList.pop();
    if (!ok[x][y])
      for (int j = 0; j < col[a[x][y]].size(); j++) {
        int xx = col[a[x][y]][j].first;
        int yy = col[a[x][y]][j].second;
        ok[xx][yy] = true;
        if (d[c][xx][yy] > d[c][x][y] + 1) {
          d[c][xx][yy] = d[c][x][y] + 1;
          CurrList.push(pair<int, int>(xx, yy));
        }
      }
    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (1 <= xx && xx <= n && 1 <= yy && yy <= m)
        if (d[c][xx][yy] > d[c][x][y] + 1) {
          d[c][xx][yy] = d[c][x][y] + 1;
          CurrList.push(pair<int, int>(xx, yy));
        }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      col[a[i][j]].push_back(pair<int, int>(i, j));
    }
  for (int i = 1; i <= 40; i++) cal(i);
  cin >> q;
  while (q--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (int i = 1; i <= 40; i++)
      ans = min(ans, d[i][x1][y1] + d[i][x2][y2] + 1);
    cout << ans << '\n';
  }
}
