#include <bits/stdc++.h>
using namespace std;
const int maxn = 1020, maxk = 50;
int a[maxn][maxn], n, m, k, q, dis[maxk][maxn][maxn];
vector<pair<int, int>> color_count[maxk];
bool colormark[maxk], vmark[maxn][maxn];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void cl() {
  for (int i = 0; i <= n + 2; i++)
    for (int j = 0; j <= m + 2; j++) vmark[i][j] = 0;
  for (int i = 0; i <= k + 2; i++) colormark[i] = 0;
}
void bfs(int color) {
  queue<pair<int, int>> tea;
  colormark[color] = 1;
  for (pair<int, int> i : color_count[color])
    tea.push(i), vmark[i.first][i.second] = 1;
  while (tea.size()) {
    int x = tea.front().first, y = tea.front().second;
    tea.pop();
    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx <= n && xx > 0 && yy <= m && yy > 0 && !vmark[xx][yy]) {
        dis[color][xx][yy] = dis[color][x][y] + 1;
        vmark[xx][yy] = 1;
        tea.push(make_pair(xx, yy));
      }
    }
    if (!colormark[a[x][y]]) {
      colormark[a[x][y]] = 1;
      for (pair<int, int> i : color_count[a[x][y]]) {
        int x2 = i.first, y2 = i.second;
        if (!vmark[x2][y2]) {
          dis[color][x2][y2] = dis[color][x][y] + 1;
          vmark[x2][y2] = 1;
          tea.push(make_pair(x2, y2));
        }
      }
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      color_count[a[i][j]].push_back(make_pair(i, j));
    }
  for (int i = 1; i <= k; i++) {
    cl();
    bfs(i);
  }
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = abs(r1 - r2) + abs(c1 - c2);
    for (int i = 1; i <= k; i++) {
      ans = min(ans, dis[i][r2][c2] + dis[i][r1][c1] + 1);
    }
    cout << ans << endl;
  }
  return 0;
}
