#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6 + 100;
const int maxm = 2e6 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
int n, m, k;
int a[1111][1111];
bool ck(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
int dx[5] = {0, 1, 0, -1};
int dy[5] = {1, 0, -1, 0};
int vis[44];
int c[41][1001][1001];
vector<pair<int, int> > v[44];
void bfs(int color) {
  int N = n, M = m;
  queue<pair<int, int> > q;
  for (int i = 0; i < v[color].size(); i++) {
    int r = v[color][i].first;
    int c = v[color][i].second;
    ::c[color][r][c] = 0;
    q.push(make_pair(r, c));
  }
  int mark[44];
  memset(mark, 0, sizeof(mark));
  while (!q.empty()) {
    int r = q.front().first;
    int c = q.front().second;
    q.pop();
    if (!mark[a[r][c]]) {
      mark[a[r][c]] = 1;
      for (int i = 0; i < v[a[r][c]].size(); i++) {
        int x = v[a[r][c]][i].first;
        int y = v[a[r][c]][i].second;
        if (::c[color][x][y] == -1) {
          ::c[color][x][y] = ::c[color][r][c] + 1;
          q.push(make_pair(x, y));
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      int x = r + dx[i];
      int y = c + dy[i];
      if (x > 0 && x <= N && y > 0 && y <= M && ::c[color][x][y] == -1) {
        ::c[color][x][y] = ::c[color][r][c] + 1;
        q.push(make_pair(x, y));
      }
    }
  }
}
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", &a[i][j]);
      v[a[i][j]].push_back(make_pair(i, j));
    }
  }
  memset(c, -1, sizeof(c));
  for (int i = 1; i <= k; i++) {
    bfs(i);
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (int i = 1; i <= k; i++) {
      ans = min(ans, c[i][x1][y1] + c[i][x2][y2] + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
