#include <bits/stdc++.h>
using namespace std;
const int MAXK = 40;
const int MAXN = 1000;
int nbLignes, nbColonnes, K;
int dist[MAXK][MAXN][MAXN];
int tab[MAXN][MAXN];
int D[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
vector<pair<int, int> > appartient[MAXK];
bool dedans(int x, int y) {
  if (x < 0 || y < 0 || x >= nbLignes || y >= nbColonnes) return false;
  return true;
}
void bfs(int couleur) {
  bool vu[MAXK];
  for (int i = 0; i < K; i++) vu[i] = false;
  vu[couleur] = true;
  deque<int> enCours;
  for (int i = 0; i < nbLignes; i++) {
    for (int j = 0; j < nbColonnes; j++) {
      if (tab[i][j] == couleur) {
        enCours.push_back(i);
        enCours.push_back(j);
        enCours.push_back(0);
      }
      dist[couleur][i][j] = -1;
    }
  }
  while (!enCours.empty()) {
    int x = enCours.front();
    enCours.pop_front();
    int y = enCours.front();
    enCours.pop_front();
    int d = enCours.front();
    enCours.pop_front();
    if (dist[couleur][x][y] != -1) continue;
    dist[couleur][x][y] = d;
    if (!vu[tab[x][y]]) {
      vu[tab[x][y]] = true;
      for (int i = 0; i < appartient[tab[x][y]].size(); i++) {
        pair<int, int> ac = appartient[tab[x][y]][i];
        enCours.push_back(ac.first);
        enCours.push_back(ac.second);
        enCours.push_back(d + 1);
      }
    }
    for (int i = 0; i < 4; i++) {
      int nx = x + D[i][0];
      int ny = y + D[i][1];
      if (dedans(nx, ny)) {
        enCours.push_back(nx);
        enCours.push_back(ny);
        enCours.push_back(d + 1);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> nbLignes >> nbColonnes >> K;
  for (int i = 0; i < nbLignes; i++) {
    for (int j = 0; j < nbColonnes; j++) {
      cin >> tab[i][j];
      tab[i][j]--;
      appartient[tab[i][j]].push_back({i, j});
    }
  }
  for (int i = 0; i < K; i++) {
    bfs(i);
  }
  int nbQuestions;
  cin >> nbQuestions;
  for (int i = 0; i < nbQuestions; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    x2--;
    y2--;
    int distMin = abs(x1 - x2) + abs(y1 - y2);
    for (int j = 0; j < K; j++) {
      distMin = min(distMin, 1 + dist[j][x1][y1] + dist[j][x2][y2]);
    }
    cout << distMin << endl;
  }
}
