#include <bits/stdc++.h>
using namespace std;
const long long N = 61;
long long n, m, r;
long long dist[N][N][N], cache[N][N][N];
long long ans[N][N][N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(cache, -1, sizeof(cache));
  cin >> n >> m >> r;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      for (long long k = 1; k <= n; k++) cin >> dist[i][j][k];
    }
  }
  for (long long car = 1; car <= m; car++)
    for (long long k = 1; k <= n; k++)
      for (long long i = 1; i <= n; i++)
        for (long long j = 1; j <= n; j++)
          dist[car][i][j] =
              min(dist[car][i][j], dist[car][i][k] + dist[car][k][j]);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      ans[i][j][0] = 2e9;
      for (long long car = 1; car <= m; car++)
        ans[i][j][0] = min(ans[i][j][0], dist[car][i][j]);
    }
  }
  for (long long k = 1; k <= n; k++) {
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; j++) {
        ans[i][j][k] = 2e9;
        for (long long mid = 1; mid <= n; mid++)
          ans[i][j][k] = min(ans[i][j][k], ans[i][mid][k - 1] + ans[mid][j][0]);
      }
    }
  }
  while (r--) {
    long long s, t, k;
    cin >> s >> t >> k;
    k = min(n, k);
    long long answer = ans[s][t][k];
    cout << answer << "\n";
  }
  return 0;
}
