#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, r;
  cin >> n >> m >> r;
  static long long dp[1001][60][60];
  int i, j, k, l, z;
  for (j = 0; j < n; j++)
    for (k = 0; k < n; k++) dp[0][j][k] = INT_MAX;
  long long mat[n][n];
  for (z = 0; z < m; z++) {
    for (j = 0; j < n; j++)
      for (k = 0; k < n; k++) cin >> mat[j][k];
    for (k = 0; k < n; ++k)
      for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
          mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
    for (j = 0; j < n; j++)
      for (k = 0; k < n; k++) dp[0][j][k] = min(dp[0][j][k], mat[j][k]);
  }
  for (i = 1; i <= 61; ++i) {
    for (j = 0; j < n; ++j) {
      for (k = 0; k < n; ++k) {
        dp[i][j][k] = dp[i - 1][j][k];
        for (l = 0; l < n; ++l) {
          dp[i][j][k] = min(dp[i][j][k], min(dp[0][j][l] + dp[i - 1][l][k],
                                             dp[i - 1][j][l] + dp[0][l][k]));
        }
      }
    }
  }
  int t, s, switches;
  for (int i = 0; i < r; i++) {
    cin >> t >> s >> switches;
    cout << dp[min(switches, 61)][t - 1][s - 1] << endl;
  }
}
