#include <bits/stdc++.h>
using namespace std;
inline void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &$val, const Args &...args) {
  string $name;
  *iss >> $name;
  if ($name.back() == ',') $name.pop_back();
  cout << $name << " = " << $val << "; ", err(iss, args...);
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll llinf = (1ll << 61) - 1;
int n, m, K, T, Q, cn;
int dist[65][65][65], d[65][65][1005];
int main() {
  cin.tie(NULL);
  scanf("%d%d%d", &n, &m, &Q);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        scanf("%d", &dist[i][j][k]);
      }
    }
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < n; l++) {
          dist[i][k][l] = min(dist[i][k][l], dist[i][k][j] + dist[i][j][l]);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j][0] = 1000000007;
      for (int k = 0; k < m; k++) {
        d[i][j][0] = min(d[i][j][0], dist[k][i][j]);
      }
    }
  }
  for (int i = 1; i <= 1005 - 1; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        d[j][k][i] = d[j][k][i - 1];
        for (int l = 0; l < n; l++) {
          d[j][k][i] = min(d[j][k][i], d[j][l][0] + d[l][k][i - 1]);
        }
      }
    }
  }
  while (Q--) {
    int s, t;
    scanf("%d%d%d", &s, &t, &K);
    printf("%d\n", d[--s][--t][K]);
  }
  return 0;
}
