#include <bits/stdc++.h>
using namespace std;
long long int a[62][62][62], dp[62][62], dp2[62][62][62];
int main() {
  int n, m, r, i, j, k, x;
  int s, t;
  scanf("%d %d %d", &n, &m, &r);
  for (i = 0; i <= 61; i++)
    for (j = 0; j <= 61; j++)
      for (k = 0; k <= 61; k++) dp2[i][j][k] = dp[i][j] = 10000000000LL;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++)
      for (k = 1; k <= n; k++) {
        cin >> a[i][j][k];
        dp[j][k] = a[i][j][k];
      }
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        for (x = 1; x <= n; x++) {
          dp[k][x] = min(dp[k][x], dp[k][j] + dp[j][x]);
        }
      }
    }
    for (j = 1; j <= n; j++)
      for (k = 1; k <= n; k++) dp2[j][k][0] = min(dp2[j][k][0], dp[j][k]);
  }
  for (k = 1; k <= 61; k++)
    for (x = 1; x <= n; x++)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
          dp2[i][j][k] = min(dp2[i][j][k], dp2[i][x][k - 1] + dp2[x][j][0]);
  while (r--) {
    cin >> s >> t >> k;
    cout << dp2[s][t][min(k, 61)] << endl;
  }
  return 0;
}
