#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, m, r;
    cin >> n >> m >> r;
    long long spd[m + 1][n][n], dp[n + 1][n + 1][n + 1];
    for (long long int i = 0; i < m; i++) {
      for (long long int j = 0; j < n; j++) {
        for (long long int k = 0; k < n; k++) {
          cin >> spd[i][j][k];
        }
      }
    }
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < n; j++) dp[i][j][0] = 1e7;
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < n; j++)
        for (long long int k = 0; k < n; k++) dp[i][j][k] = 1e7;
    for (long long int car = 0; car < m; car++) {
      long long dp1[60][60];
      for (long long int i = 0; i < n; i++)
        for (long long int j = 0; j < n; j++) dp1[i][j] = spd[car][i][j];
      for (long long int k = 0; k < n; k++)
        for (long long int i = 0; i < n; i++)
          for (long long int j = 0; j < n; j++) {
            dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]);
            dp[i][j][0] = min(dp[i][j][0], dp1[i][j]);
          }
    }
    for (long long int ch = 1; ch < n; ch++) {
      for (long long int k = 0; k < n; k++) {
        for (long long int i = 0; i < n; i++) {
          for (long long int j = 0; j < n; j++) {
            dp[i][j][ch] = min(dp[i][j][ch], dp[i][k][ch - 1] + dp[k][j][0]);
          }
        }
      }
    }
    for (long long int i = 0; i < r; i++) {
      long long s, t, cho;
      cin >> s >> t >> cho;
      cout << dp[s - 1][t - 1][min(cho, n - 1)] << "\n";
    }
  }
  return 0;
}
