#include <bits/stdc++.h>
const int mod = 998244353;
using namespace std;
int n, m, k;
int g[1010][1010];
vector<pair<int, int>> gg[100];
int dis[1002][1002][45];
int v[1002][1002];
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int vv[50];
void bfs(int c) {
  queue<pair<int, int>> q;
  for (int i = 1; i < k + 1; ++i) vv[i] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      v[i][j] = 0;
      if (g[i][j] == c) {
        q.push(make_pair(i, j));
        dis[i][j][c] = 0;
        v[i][j] = 1;
      }
    }
  }
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    v[x][y] = 0;
    for (int i = 0; i < 4; ++i) {
      int xx = x + d[i][0];
      int yy = y + d[i][1];
      if (xx >= 0 && yy >= 0 && xx < n && yy < m) {
        if (dis[xx][yy][c] == -1) {
          dis[xx][yy][c] = dis[x][y][c] + 1;
          if (!v[xx][yy]) {
            q.push(make_pair(xx, yy));
            v[xx][yy] = 1;
          }
        }
      }
    }
    if (!vv[g[x][y]]) {
      vv[g[x][y]] = 1;
      for (auto t_x : gg[g[x][y]]) {
        int xx = t_x.first;
        int yy = t_x.second;
        if (xx >= 0 && yy >= 0 && xx < n && yy < m) {
          if (dis[xx][yy][c] == -1) {
            dis[xx][yy][c] = dis[x][y][c] + 1;
            if (!v[xx][yy]) {
              q.push(make_pair(xx, yy));
              v[xx][yy] = 1;
            }
          }
        }
      }
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &g[i][j]);
      gg[g[i][j]].push_back(make_pair(i, j));
    }
  }
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i < k + 1; ++i) {
    bfs(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x1--;
    y1--;
    x2--;
    y2--;
    int c1 = g[x1][y1];
    int c2 = g[x2][y2];
    int ans = abs(x2 - x1) + abs(y2 - y1);
    for (int i = 1; i < k + 1; ++i) {
      ans = min(ans, dis[x1][y1][i] + dis[x2][y2][i] + 1);
    }
    printf("%d\n", ans);
  }
}
