#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N][N], n, m, k, dis[50][N][N], visit[N][N], visit_c[N];
vector<pair<int, int> > vt[50];
pair<int, int> dir[4] = {make_pair(0, 1), make_pair(0, -1), make_pair(1, 0),
                         make_pair(-1, 0)};
void read() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
}
void bfs(int x) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) visit[i][j] = 0;
  for (int i = 1; i <= k; i++) visit_c[i] = 0;
  queue<pair<int, int> > q;
  for (pair<int, int> p : vt[x]) visit[p.first][p.second] = 1, q.push(p);
  visit_c[x] = 1;
  while (!q.empty()) {
    int u = q.front().first, v = q.front().second, w = a[u][v];
    q.pop();
    for (int i = 0; i < 4; i++) {
      int r = u + dir[i].first;
      int c = v + dir[i].second;
      if (a[r][c] && !visit[r][c]) {
        visit[r][c] = 1;
        dis[x][r][c] = dis[x][u][v] + 1;
        q.push(make_pair(r, c));
      }
    }
    if (!visit_c[w]) {
      visit_c[w] = 1;
      for (pair<int, int> p : vt[w])
        if (!visit[p.first][p.second]) {
          visit[p.first][p.second] = 1;
          dis[x][p.first][p.second] = dis[x][u][v] + 1;
          q.push(p);
        }
    }
  }
}
void process() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) vt[a[i][j]].push_back(make_pair(i, j));
  for (int i = 1; i <= k; i++) bfs(i);
  int q;
  cin >> q;
  for (int i = 1, x, y, u, v; i <= q; i++) {
    cin >> x >> y >> u >> v;
    int res = abs(x - u) + abs(y - v);
    for (int j = 1; j <= k; j++)
      res = min(res, dis[j][x][y] + dis[j][u][v] + 1);
    cout << res << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  read();
  process();
  return 0;
}
