#include <bits/stdc++.h>
using namespace std;
const long long N = 65;
const long long oo = 1e18 + 100;
long long dist[N][N][N], dp[N][N][N], W[N][N][N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  long long r;
  cin >> r;
  memset(dp, 0x3f, sizeof dp);
  memset(dist, 0x3f, sizeof dist);
  memset(W, 0x3f, sizeof W);
  for (long long i = 1; i <= m; i++)
    for (long long j = 1; j <= n; j++)
      for (long long t = 1; t <= n; t++) {
        long long w;
        cin >> w;
        dist[i][j][t] = w;
        W[i][j][t] = w;
      }
  for (long long t = 1; t <= m; t++)
    for (long long k = 1; k <= n; k++)
      for (long long i = 1; i <= n; i++)
        for (long long j = 1; j <= n; j++) {
          W[t][i][j] = min(W[t][i][j], W[t][i][k] + W[t][k][j]);
          dp[0][i][j] = min(dp[0][i][j], W[t][i][j]);
        }
  for (long long t = 1; t <= n; t++)
    for (long long k = 1; k <= n; k++)
      for (long long i = 1; i <= n; i++)
        for (long long j = 1; j <= n; j++) {
          dp[t][i][j] = min(dp[t][i][j], dp[t - 1][i][k] + dp[0][k][j]);
        }
  for (long long s, t, k, i = 1; i <= r; i++) {
    cin >> s >> t >> k;
    k = min(k, n);
    cout << dp[k][s][t] << '\n';
  }
  return 0;
}
