#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3, K = 40;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool mark[K];
vector<pair<int, int>> vc[K];
int dist[K][MAXN][MAXN], a[MAXN][MAXN];
int qs, n, m, k;
queue<pair<int, int>> q;
void input();
void bfs(int);
void solve();
void output();
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input();
  solve();
  output();
  return 0;
}
void input() {
  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]--;
      vc[a[i][j]].push_back({i, j});
    }
}
bool is_valid(int x, int y) { return x >= 0 && y >= 0 && y < m && x < n; }
void bfs(int r) {
  for (auto i : vc[r]) {
    dist[r][i.first][i.second] = 0;
    q.push({i.first, i.second});
  }
  mark[r] = true;
  while (!q.empty()) {
    pair<int, int> x = q.front();
    int ds = dist[r][x.first][x.second];
    q.pop();
    if (!mark[a[x.first][x.second]])
      for (auto i : vc[a[x.first][x.second]])
        if (dist[r][i.first][i.second] > ds + 1) {
          dist[r][i.first][i.second] = ds + 1;
          q.push({i.first, i.second});
        }
    mark[a[x.first][x.second]] = true;
    for (int i = 0; i < 4; i++)
      if (is_valid(x.first + dx[i], x.second + dy[i]))
        if (dist[r][x.first + dx[i]][x.second + dy[i]] > ds + 1) {
          dist[r][x.first + dx[i]][x.second + dy[i]] = ds + 1;
          q.push({x.first + dx[i], x.second + dy[i]});
        }
  }
}
void solve() {
  memset(dist, 63, sizeof dist);
  for (int i = 0; i < k; i++) {
    bfs(i);
    for (int j = 0; j < k; j++) mark[j] = false;
  }
}
void output() {
  cin >> qs;
  while (qs--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--, c1--, r2--, c2--;
    if (r1 == r2 && c1 == c2)
      cout << 0 << endl;
    else {
      int ans = abs(r1 - r2) + abs(c1 - c2);
      for (int i = 0; i < k; i++)
        ans = min(ans, dist[i][r1][c1] + dist[i][r2][c2] + 1);
      cout << ans << endl;
    }
  }
}
