#include <bits/stdc++.h>
int dp[61][61][61];
int g[61][61][61];
struct node {
  int s, t, k;
} s[100010];
int main() {
  int n, m, r;
  while (scanf("%d %d %d", &n, &m, &r) != EOF) {
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++) scanf("%d", &g[i][j][k]);
    for (int t = 1; t <= m; t++)
      for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
          for (int j = 1; j <= n; j++)
            if (g[t][i][j] > g[t][i][k] + g[t][k][j])
              g[t][i][j] = g[t][i][k] + g[t][k][j];
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        dp[0][i][j] = 1e9;
        for (int k = 1; k <= m; k++) {
          if (dp[0][i][j] > g[k][i][j]) dp[0][i][j] = g[k][i][j];
        }
      }
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
          if (i != j) {
            dp[k][i][j] = 1e9;
            for (int t = 1; t <= n; t++)
              if (dp[k][i][j] > dp[0][i][t] + dp[k - 1][t][j])
                dp[k][i][j] = dp[0][i][t] + dp[k - 1][t][j];
          }
        }
    while (r--) {
      int ss, tt, cnt;
      scanf("%d %d %d", &ss, &tt, &cnt);
      if (cnt > n) cnt = n;
      printf("%d\n", dp[cnt][ss][tt]);
    }
  }
  return 0;
}
