#include <bits/stdc++.h>
using namespace std;
int n, m, k, dist[41][1005][1005];
int mat[1005][1005], vis[50];
vector<pair<int, int> > adj[50];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool valid(int x, int y) { return x >= 1 and x <= n and y >= 1 and y <= m; }
void solve(int cor) {
  memset(vis, 0, sizeof vis);
  queue<pair<int, int> > q;
  for (pair<int, int> par : adj[cor]) {
    q.push(par);
    dist[cor][par.first][par.second] = 0;
  }
  vis[cor] = 1;
  while (!q.empty()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();
    if (!vis[mat[x][y]]) {
      vis[mat[x][y]] = 1;
      for (pair<int, int> p : adj[mat[x][y]]) {
        int xx = p.first, yy = p.second;
        if (dist[cor][x][y] + 1 < dist[cor][xx][yy]) {
          dist[cor][xx][yy] = dist[cor][x][y] + 1;
          q.push({xx, yy});
        }
      }
    }
    for (int i = 0; i < 4; ++i) {
      int xx = x + dx[i], yy = y + dy[i];
      if (valid(xx, yy) && dist[cor][x][y] + 1 < dist[cor][xx][yy]) {
        dist[cor][xx][yy] = dist[cor][x][y] + 1;
        q.push({xx, yy});
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mat[i][j]);
      adj[mat[i][j]].push_back({i, j});
    }
  for (int l = 1; l <= k; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) dist[l][i][j] = 1e9;
  for (int i = 1; i <= k; i++) solve(i);
  int q;
  scanf("%d", &q);
  while (q--) {
    int r1, c1, r2, c2;
    scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
    int res = abs(r1 - r2) + abs(c1 - c2);
    int cor1 = mat[r1][c1];
    int cor2 = mat[r2][c2];
    for (int i = 1; i <= k; i++)
      res = min(res, dist[i][r1][c1] + dist[i][r2][c2] + 1);
    printf("%d\n", res);
  }
  return 0;
}
