#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0', ch = getchar();
  }
  return x * f;
}
const int inf = 0x3f3f3f3f;
const int maxn = 1e3 + 50;
int n, m, k, st1, ed1, st2, ed2, col[maxn][maxn], f[45][maxn][maxn], visc[maxn];
vector<pair<int, int>> v[maxn];
int vis[maxn][maxn], dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
struct node {
  int x, y, step;
  node(){};
  node(int x, int y, int step) : x(x), y(y), step(step){};
};
bool check(node now) {
  if (now.x < 1 || now.y < 1 || now.x > n || now.y > m) return false;
  if (vis[now.x][now.y]) return false;
  return true;
}
void bfs(int x) {
  memset(vis, 0, sizeof vis);
  memset(visc, 0, sizeof visc);
  queue<node> q;
  for (int i = 0; i < v[x].size(); ++i) {
    q.push(node(v[x][i].first, v[x][i].second, 0));
    f[x][v[x][i].first][v[x][i].second] = 0;
    vis[v[x][i].first][v[x][i].second] = 1;
  }
  visc[x] = 1;
  while (!q.empty()) {
    node now = q.front();
    q.pop();
    vis[now.x][now.y] = 1;
    for (int i = 0; i < 4; ++i) {
      node next;
      next.x = now.x + dir[i][0], next.y = now.y + dir[i][1],
      next.step = now.step + 1;
      if (check(next)) {
        q.push(next);
        vis[next.x][next.y] = 1;
        f[x][next.x][next.y] = f[x][now.x][now.y] + 1;
      }
    }
    if (!visc[col[now.x][now.y]]) {
      visc[col[now.x][now.y]] = 1;
      for (auto z : v[col[now.x][now.y]]) {
        node next;
        next.x = z.first, next.y = z.second, next.step = now.step + 1;
        if (check(next)) {
          q.push(next);
          vis[next.x][next.y] = 1;
          f[x][next.x][next.y] = f[x][now.x][now.y] + 1;
        }
      }
    }
  }
}
int main() {
  n = rd(), m = rd(), k = rd();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int x;
      x = rd();
      col[i][j] = x;
      v[x].push_back(make_pair(i, j));
    }
  }
  memset(f, inf, sizeof f);
  for (int i = 0; i < 43; ++i) {
    bfs(i);
  }
  int t;
  t = rd();
  for (int i = 0; i < t; ++i) {
    st1 = rd(), ed1 = rd(), st2 = rd(), ed2 = rd();
    int minn = abs(st1 - st2) + abs(ed1 - ed2);
    for (int i = 0; i < 43; ++i) {
      minn = min(minn, f[i][st1][ed1] + f[i][st2][ed2] + 1);
    }
    cout << minn << endl;
  }
  return 0;
}
