#include <bits/stdc++.h>
using namespace std;
const int MAXM = 1e5;
const int INF = 0x3f3f3f3f;
const long long MOD = 100000007;
const int SIZE = 1010;
int n, m, r;
int cost[66][66][66];
int dp[1010][66][66];
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) scanf("%d", &cost[i][j][k]);
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int p = 1; p <= n; p++)
          cost[i][k][p] = min(cost[i][k][p], cost[i][k][j] + cost[i][j][p]);
      }
    }
  }
  memset(dp, INF, sizeof(dp));
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int p = 1; p <= n; p++)
          dp[0][j][k] = min(dp[0][j][k], cost[i][j][p] + cost[i][p][k]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int p = 1; p <= n; p++)
          dp[i][k][p] = min(dp[i][k][p], dp[i - 1][k][j] + dp[0][j][p]);
      }
    }
  }
  while (r--) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    k = min(k, n);
    int ans = INF;
    for (int i = 0; i <= k; i++) ans = min(ans, dp[i][s][t]);
    printf("%d\n", ans);
  }
  return 0;
}
