#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long dp[61][61][61];
int b[61][61][61];
int main() {
  int n, m, r;
  memset(dp, 0x3f, sizeof(dp));
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= n; l++) scanf("%d", &b[i][j][l]);
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= n; l++)
        for (int p = 1; p <= n; p++)
          b[i][l][p] = min(b[i][l][p], b[i][l][j] + b[i][j][p]);
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= n; l++)
        dp[j][l][0] = min((long long)b[i][j][l], dp[j][l][0]);
  }
  for (int i = 1; i <= 60; i++)
    for (int j = 1; j <= n; j++) {
      for (int l = 1; l <= n; l++) {
        for (int p = 1; p <= n; p++) {
          dp[j][l][i] = min(dp[j][l][i], dp[j][p][i - 1] + dp[p][l][0]);
        }
      }
    }
  int s, t, k;
  while (r--) {
    scanf("%d%d%d", &s, &t, &k);
    if (k > 60) k = 60;
    printf("%I64d\n", dp[s][t][k]);
  }
}
