#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vpii = vector<pair<int, int>>;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
void R() {}
template <class T, class... U>
inline void R(T &head, U &...tail) {
  cin >> head;
  R(tail...);
}
void W() {}
template <class T, class... U>
inline void W(const T &head, const U &...tail) {
  cout << head << (sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <class T>
void W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); cout << (*i++)) {
    if (i != x.cbegin()) cout << ' ';
  }
  cout << '\n';
}
template <class T>
inline void cmax(T &a, T b) {
  a = max(a, b);
}
template <class T>
inline void cmin(T &a, T b) {
  a = min(a, b);
}
mt19937 rng(time(0));
int n, m, K, maze[1010][1010];
int vis_color[45], vis[1010][1010];
int dis[45][1010][1010];
vpii color[45];
const int b[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
void pre(int id) {
  memset(vis, 0, sizeof vis);
  memset(vis_color, 0, sizeof vis_color);
  queue<pii> q;
  for (auto t : color[id]) {
    int x = t.first, y = t.second;
    q.push(pii(x, y));
    vis[x][y] = 1;
    dis[id][x][y] = 0;
  }
  vis_color[id] = 1;
  while (q.size()) {
    pii cur = q.front();
    q.pop();
    int x = cur.first, y = cur.second;
    if (!vis_color[maze[x][y]]) {
      vis_color[maze[x][y]] = 1;
      for (auto t : color[maze[x][y]]) {
        int xx = t.first, yy = t.second;
        if (vis[xx][yy]) continue;
        q.push(pii(xx, yy));
        vis[xx][yy] = 1;
        dis[id][xx][yy] = dis[id][x][y] + 1;
      }
    }
    for (int i = (0); i < (int)(4); ++i) {
      int xx = x + b[i][0];
      int yy = y + b[i][1];
      if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;
      if (vis[xx][yy]) continue;
      vis[xx][yy] = 1;
      q.push(pii(xx, yy));
      dis[id][xx][yy] = dis[id][x][y] + 1;
    }
  }
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  R(n, m, K);
  for (int i = (1); i <= (int)(n); ++i)
    for (int j = (1); j <= (int)(m); ++j) {
      R(maze[i][j]);
      color[maze[i][j]].push_back(pii(i, j));
    }
  for (int i = (1); i <= (int)(K); ++i) pre(i);
  int Q;
  R(Q);
  while (Q--) {
    int sx, sy, ex, ey;
    R(sx, sy, ex, ey);
    int an = abs(sx - ex) + abs(sy - ey);
    for (int i = (1); i <= (int)(K); ++i)
      an = min(an, 1 + dis[i][sx][sy] + dis[i][ex][ey]);
    W(an);
  }
  return 0;
}
