#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 1000, K_MAX = 40;
int n, m, k, q, a[N_MAX][N_MAX], d[K_MAX][N_MAX][N_MAX],
    t[2 * K_MAX][2 * K_MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  for (int c = 0; c < k; c++) {
    queue<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] == c)
          s.push({i, j});
        else
          d[c][i][j] = -1;
      }
    }
    while (!s.empty()) {
      int i = s.front().first, j = s.front().second;
      s.pop();
      if (0 < i && d[c][i - 1][j] == -1) {
        d[c][i - 1][j] = d[c][i][j] + 1;
        s.push({i - 1, j});
      }
      if (i + 1 < n && d[c][i + 1][j] == -1) {
        d[c][i + 1][j] = d[c][i][j] + 1;
        s.push({i + 1, j});
      }
      if (0 < j && d[c][i][j - 1] == -1) {
        d[c][i][j - 1] = d[c][i][j] + 1;
        s.push({i, j - 1});
      }
      if (j + 1 < m && d[c][i][j + 1] == -1) {
        d[c][i][j + 1] = d[c][i][j] + 1;
        s.push({i, j + 1});
      }
    }
  }
  for (int u = 0; u < 2 * k; u++)
    for (int v = 0; v < 2 * k; v++) t[u][v] = 1e7;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int c = 0; c < k; c++)
        t[a[i][j] + k][c] = min(t[a[i][j] + k][c], d[c][i][j]);
  for (int u = 0; u < 2 * k; u++) t[u][u] = 0;
  for (int u = 0; u < k; u++) t[u][u + k] = 1;
  for (int w = 0; w < 2 * k; w++)
    for (int u = 0; u < 2 * k; u++)
      for (int v = 0; v < 2 * k; v++) t[u][v] = min(t[u][v], t[u][w] + t[w][v]);
  cin >> q;
  while (q--) {
    int i1, j1, i2, j2;
    cin >> i1 >> j1 >> i2 >> j2;
    i1--;
    j1--;
    i2--;
    j2--;
    int sol = abs(i1 - i2) + abs(j1 - j2);
    for (int c1 = 0; c1 < k; c1++)
      for (int c2 = 0; c2 < k; c2++)
        sol = min(sol, d[c1][i1][j1] + t[c1][c2 + k] + d[c2][i2][j2]);
    cout << sol << "\n";
  }
  return 0;
}
