#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
vector<node> col[50];
bool vis[1010][1010], vc[100];
int n, m, k;
int a[1010][1010], dis[41][1010][1010];
int d[4][2] = {0, 1, 0, -1, -1, 0, 1, 0};
void bfs(int c) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) vis[i][j] = 0;
  for (int i = 1; i <= k; i++) vc[i] = 0;
  queue<node> q;
  while (q.size()) q.pop();
  for (int i = 0; i < col[c].size(); i++) {
    q.push({col[c][i].x, col[c][i].y});
    vis[col[c][i].x][col[c][i].y] = 1;
  }
  vc[c] = 1;
  while (q.size()) {
    node tmp = q.front();
    q.pop();
    if (vc[a[tmp.x][tmp.y]] == 0) {
      for (int i = 0; i < col[a[tmp.x][tmp.y]].size(); i++) {
        int x = col[a[tmp.x][tmp.y]][i].x, y = col[a[tmp.x][tmp.y]][i].y;
        if (vis[x][y]) continue;
        vis[x][y] = 1;
        dis[c][x][y] = dis[c][tmp.x][tmp.y] + 1;
        q.push(col[a[tmp.x][tmp.y]][i]);
      }
      vc[a[tmp.x][tmp.y]] = 1;
    }
    for (int i = 0; i < 4; i++) {
      int x = tmp.x + d[i][0], y = tmp.y + d[i][1];
      if (x < 1 || x > n || y < 1 || y > m || vis[x][y]) continue;
      vis[x][y] = 1;
      dis[c][x][y] = dis[c][tmp.x][tmp.y] + 1;
      q.push({x, y});
    }
  }
}
int main() {
  cin >> n >> m >> k;
  set<int> st;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      col[a[i][j]].push_back({i, j});
      st.insert(a[i][j]);
    }
  }
  for (auto it : st) bfs(it);
  int q;
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    int ans = abs(r1 - r2) + abs(c1 - c2);
    for (int i : st) {
      ans = min(ans, dis[i][r1][c1] + dis[i][r2][c2] + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
