#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, m, k;
vector<pair<int, int> > col[45];
int a[maxn][maxn];
int dis[45][maxn][maxn];
int vis[maxn][maxn], viscol[45];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void bfs(int x) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      vis[i][j] = 0;
    }
  }
  for (int i = 1; i <= k; i++) viscol[i] = 0;
  viscol[x] = 1;
  queue<pair<int, int> > Q;
  for (int i = 0; i < col[x].size(); i++) {
    Q.push(col[x][i]);
    dis[x][col[x][i].first][col[x][i].second] = 0;
    vis[col[x][i].first][col[x][i].second] = 1;
  }
  while (!Q.empty()) {
    int nowx = Q.front().first;
    int nowy = Q.front().second;
    Q.pop();
    if (!viscol[a[nowx][nowy]]) {
      for (int i = 0; i < col[a[nowx][nowy]].size(); i++) {
        int nx = col[a[nowx][nowy]][i].first;
        int ny = col[a[nowx][nowy]][i].second;
        if (vis[nx][ny] == 0) {
          dis[x][nx][ny] = 1 + dis[x][nowx][nowy];
          vis[nx][ny] = 1;
          Q.push({nx, ny});
        }
      }
      viscol[a[nowx][nowy]] = 1;
    }
    for (int i = 0; i < 4; i++) {
      int nx = nowx + dx[i];
      int ny = nowy + dy[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (vis[nx][ny] == 0) {
        dis[x][nx][ny] = 1 + dis[x][nowx][nowy];
        vis[nx][ny] = 1;
        Q.push({nx, ny});
      }
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      col[a[i][j]].push_back({i, j});
    }
  }
  for (int i = 1; i <= k; i++) {
    bfs(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int r1, c1, r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    r1--, c1--, r2--, c2--;
    int ans = abs(r2 - r1) + abs(c1 - c2);
    for (int j = 1; j <= k; j++) {
      ans = min(ans, dis[j][r1][c1] + dis[j][r2][c2] + 1);
    }
    printf("%d\n", ans);
  }
}
