#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
const int maxk = 40 + 5;
int n, m, k, q;
int di[] = {0, -1, 0, 1};
int dj[] = {-1, 0, 1, 0};
vector<pair<int, int> > col[maxk];
int mask[maxn][maxn];
int cost[maxk][maxn][maxn];
bool vis[maxk];
void bfs(int c) {
  for (int i = 0; i < k; ++i) vis[i] = false;
  vis[c] = true;
  queue<pair<int, int> > Q;
  for (auto& p : col[c]) {
    Q.push(p);
    cost[c][p.first][p.second] = 0;
  }
  while (!Q.empty()) {
    pair<int, int> v = Q.front();
    Q.pop();
    if (!vis[mask[v.first][v.second]]) {
      vis[mask[v.first][v.second]] = true;
      for (auto& u : col[mask[v.first][v.second]])
        if (cost[c][u.first][u.second] == -1) {
          cost[c][u.first][u.second] = cost[c][v.first][v.second] + 1;
          Q.push(u);
        }
    }
    for (int i = 0; i < 4; ++i) {
      int ii = v.first + di[i];
      int jj = v.second + dj[i];
      if (ii < 0 || ii >= n || jj < 0 || jj >= m || cost[c][ii][jj] != -1)
        continue;
      cost[c][ii][jj] = cost[c][v.first][v.second] + 1;
      Q.push(make_pair(ii, jj));
    }
  }
}
template <typename T>
T getint() {
  T val = 0;
  char c;
  bool neg = false;
  while ((c = getchar()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val * (neg ? -1 : 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  n = getint<int>();
  m = getint<int>();
  k = getint<int>();
  for (int c = 0; c < k; ++c)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) cost[c][i][j] = -1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      int a;
      a = getint<int>() - 1;
      col[a].push_back(make_pair(i, j));
      mask[i][j] = a;
    }
  for (int i = 0; i < k; ++i) bfs(i);
  q = getint<int>();
  while (q--) {
    int r1, r2, c1, c2;
    r1 = getint<int>() - 1;
    c1 = getint<int>() - 1;
    r2 = getint<int>() - 1;
    c2 = getint<int>() - 1;
    int ans = abs(r2 - r1) + abs(c2 - c1);
    for (int i = 0; i < k; ++i)
      ans = min(ans, cost[i][r1][c1] + cost[i][r2][c2] + 1);
    cout << ans << '\n';
  }
}
