#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int dx[5] = {0, 1, 0, -1, 0};
const int dy[5] = {0, 0, 1, 0, -1};
int n, m, k;
int col[N][N];
int dis[50][N][N];
int vis[N][N];
int cvis[60];
struct ha {
  int x, y;
};
queue<ha> q;
vector<ha> a[60];
void Bfs(int c) {
  memset(vis, 0, sizeof(vis));
  memset(cvis, 0, sizeof(cvis));
  for (int i = 0; i < a[c].size(); i++)
    q.push(a[c][i]), dis[c][a[c][i].x][a[c][i].y] = 0,
                     vis[a[c][i].x][a[c][i].y] = 1;
  while (!q.empty()) {
    ha now = q.front();
    q.pop();
    int x = now.x, y = now.y;
    for (int i = 1; i <= 4; i++) {
      int tx = x + dx[i], ty = y + dy[i];
      if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
      if (!vis[tx][ty]) {
        vis[tx][ty] = 1;
        dis[c][tx][ty] = dis[c][x][y] + 1;
        q.push((ha){tx, ty});
      }
    }
    if (!cvis[col[x][y]]) {
      cvis[col[x][y]] = 1;
      for (int i = 0; i < a[col[x][y]].size(); i++) {
        ha to = a[col[x][y]][i];
        int tx = to.x, ty = to.y;
        if (!vis[tx][ty]) {
          vis[tx][ty] = 1;
          dis[c][tx][ty] = dis[c][x][y] + 1;
          q.push(to);
        }
      }
    }
  }
}
int main() {
  memset(dis, 0x3f, sizeof(dis));
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &col[i][j]), a[col[i][j]].push_back((ha){i, j});
  for (int i = 1; i <= k; i++) Bfs(i);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y, X, Y;
    scanf("%d %d %d %d", &x, &y, &X, &Y);
    int Ans = abs(x - X) + abs(y - Y);
    for (int j = 1; j <= k; j++)
      Ans = min(Ans, dis[j][x][y] + dis[j][X][Y] + 1);
    printf("%d\n", Ans);
  }
}
