#include <bits/stdc++.h>
using namespace std;
int arr[65][65][65], M, N, Q;
long long floyd_warshall[65][65][65], ans_dij[65][65][65],
    INF = 1ll * 1000 * 1000 * 1000 * 1000ll, race[65][65][65];
void make_dij(int c) {
  for (int i = 0; i < N + 3; i++)
    for (int j = 0; j < N + 3; j++) {
      for (int k = 0; k < N + 3; k++) {
        floyd_warshall[i][j][k] = INF;
      }
      floyd_warshall[i][j][0] = arr[c][i][j];
      ans_dij[c][i][j] = arr[c][i][j];
    }
  for (int k = 1; k <= N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        floyd_warshall[i][j][k] = min(
            floyd_warshall[i][j][k - 1],
            floyd_warshall[i][k - 1][k - 1] + floyd_warshall[k - 1][j][k - 1]);
        ans_dij[c][i][j] = min(ans_dij[c][i][j], floyd_warshall[i][j][k]);
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 0; i < M; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) scanf("%d", &arr[i][j][k]);
  for (int c = 0; c < M; c++) make_dij(c);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      race[i][j][0] = ans_dij[0][i][j];
      for (int c = 0; c < M; c++) {
        race[i][j][0] = min(race[i][j][0], ans_dij[c][i][j]);
      }
    }
  }
  for (int tx = 1; tx <= N - 1; tx++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        race[i][j][tx] = race[i][j][tx - 1];
        for (int mid = 0; mid < N; mid++) {
          race[i][j][tx] =
              min(race[i][j][tx], race[i][mid][tx - 1] + race[mid][j][0]);
        }
      }
    }
  }
  while (Q--) {
    int u, v, t;
    scanf("%d%d%d", &u, &v, &t);
    u--, v--;
    t = min(t, N - 1);
    printf("%I64d \n", (long long)race[u][v][t]);
  }
  return 0;
}
