#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream& operator<<(ostream& os, const pair<first, second>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ",";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream& operator<<(ostream& os, const map<first, second>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
void faltu() { cerr << '\n'; }
template <typename T>
void faltu(T a[], int n) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << '\n';
}
template <typename T, typename... hello>
void faltu(T arg, const hello&... rest) {
  cerr << arg << ' ';
  faltu(rest...);
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
int n, m, k;
int a[1005][1005];
vector<pair<int, int> > vec[45];
int dist[45][1005][1005];
int done[45];
void bfs(int col) {
  memset(done, -1, sizeof(done));
  queue<pair<int, int> > q;
  for (int i = 0; i < vec[col].size(); ++i) {
    q.push(make_pair(vec[col][i].first, vec[col][i].second));
    dist[col][vec[col][i].first][vec[col][i].second] = 0;
  }
  while (!q.empty()) {
    int r = q.front().first, c = q.front().second;
    q.pop();
    if (done[a[r][c]] == -1) {
      done[a[r][c]] = 1;
      for (int i = 0; i < vec[a[r][c]].size(); ++i) {
        if (make_pair(r, c) == vec[a[r][c]][i]) continue;
        if (dist[col][vec[a[r][c]][i].first][vec[a[r][c]][i].second] == -1) {
          dist[col][vec[a[r][c]][i].first][vec[a[r][c]][i].second] =
              dist[col][r][c] + 1;
          q.push(make_pair(vec[a[r][c]][i].first, vec[a[r][c]][i].second));
        }
      }
    }
    for (int i = 0; i < 4; ++i) {
      int nr = dx[i] + r, nc = dy[i] + c;
      if (nr < 1 || nr > n || nc < 1 || nc > m) continue;
      if (dist[col][nr][nc] == -1) {
        dist[col][nr][nc] = dist[col][r][c] + 1;
        q.push(make_pair(nr, nc));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(dist, -1, sizeof(dist));
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      vec[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 = 0; i < q; ++i) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = abs(r1 - r2) + abs(c1 - c2);
    for (int j = 1; j <= k; ++j) {
      ans = min(ans, dist[j][r1][c1] + dist[j][r2][c2] + 1);
    }
    cout << ans << '\n';
  }
}
