#include <bits/stdc++.h>
using namespace std;
const long long maxn = 70;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long n, m, r, a[maxn][maxn][maxn], b[maxn][maxn][maxn],
    c[maxn][maxn][maxn], s, t, x;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(b, 63, sizeof b);
  memset(c, 63, sizeof c);
  cin >> n >> m >> r;
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      for (long long k = 0; k < n; k++) {
        cin >> a[i][j][k];
        b[i][j][k] = a[i][j][k];
      }
      b[i][j][j] = 0;
    }
  }
  for (long long l = 0; l < m; l++) {
    for (long long k = 0; k < n; k++) {
      for (long long i = 0; i < n; i++) {
        for (long long j = 0; j < n; j++) {
          b[l][i][j] = min(b[l][i][j], b[l][i][k] + b[l][k][j]);
          c[0][i][j] = min(c[0][i][j], b[l][i][j]);
        }
      }
    }
  }
  for (long long k = 1; k < n; k++) {
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        for (long long l = 0; l < n; l++) {
          c[k][i][j] = min(c[k][i][j], c[0][i][l] + c[k - 1][l][j]);
        }
      }
    }
  }
  for (long long i = 0; i < r; i++) {
    cin >> s >> t >> x;
    cout << c[min(n - 1, x)][s - 1][t - 1] << '\n';
  }
  return 0;
}
