#include <bits/stdc++.h>
using namespace std;
const int maxn = 60 + 10;
int dp[maxn][maxn][maxn], cost[maxn][maxn][maxn], n, m, r;
void input(void) {
  scanf("%d", &n);
  scanf("%d %d", &m, &r);
  for (int i = (0); i <= (m - 1); i++)
    for (int j = (0); j <= (n - 1); j++)
      for (int k = (0); k <= (n - 1); k++) scanf("%d", &cost[j][k][i]);
}
void floyd(void) {
  int tmp[n][n];
  for (int i = (0); i <= (n - 1); i++)
    for (int j = (0); j <= (n - 1); j++) dp[i][j][0] = cost[i][j][0];
  for (int car = (0); car <= (m - 1); car++) {
    for (int i = (0); i <= (n - 1); i++)
      for (int j = (0); j <= (n - 1); j++) tmp[i][j] = cost[i][j][car];
    for (int i = (0); i <= (n - 1); i++)
      for (int j = (0); j <= (n - 1); j++)
        for (int k = (0); k <= (n - 1); k++)
          tmp[j][k] = min(tmp[j][k], tmp[j][i] + tmp[i][k]);
    for (int i = (0); i <= (n - 1); i++)
      for (int j = (0); j <= (n - 1); j++)
        dp[i][j][0] = min(dp[i][j][0], tmp[i][j]);
  }
  for (int i = (0); i <= (n - 1); i++)
    for (int j = (0); j <= (n - 1); j++)
      for (int change = (1); change <= (n); change++) {
        dp[i][j][change] = dp[i][j][0];
        if (i == j && dp[i][j][change] != 0)
          cout << "Bruh this is so fucked up\n";
      }
}
void answer_queries(void) {
  for (int i = (0); i <= (r - 1); i++) {
    int u, v, k;
    scanf("%d %d %d", &u, &v, &k);
    printf("%d\n", dp[u - 1][v - 1][min(k, n)]);
  }
}
int main() {
  input();
  floyd();
  for (int l = (1); l <= (n); l++)
    for (int v = (0); v <= (n - 1); v++)
      for (int i = (0); i <= (n - 1); i++)
        for (int j = (0); j <= (n - 1); j++)
          dp[i][j][l] = min(dp[i][j][l], min(dp[i][v][l - 1] + dp[v][j][0],
                                             dp[i][v][0] + dp[v][j][l - 1]));
  answer_queries();
  return 0;
}
