#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, R;
  int T[66][66][66], DP[66][66][66];
  cin >> N >> M >> R;
  for (int i = 0; i < M; ++i)
    for (int j = 0; j < N; ++j)
      for (int k = 0; k < N; ++k) scanf("%d", &T[i][j][k]);
  for (int i = 0; i < M; ++i) {
    int tmp[66][66];
    for (int s = 0; s < N; ++s)
      for (int e = 0; e < N; ++e) tmp[s][e] = T[i][s][e];
    for (int k = 0; k < N; ++k) {
      for (int s = 0; s < N; ++s)
        for (int e = 0; e < N; ++e)
          tmp[s][e] = min(tmp[s][e], T[i][s][k] + T[i][k][e]);
      for (int s = 0; s < N; ++s)
        for (int e = 0; e < N; ++e) T[i][s][e] = tmp[s][e];
    }
    if (i == 0)
      for (int s = 0; s < N; ++s)
        for (int e = 0; e < N; ++e) DP[0][s][e] = T[i][s][e];
    else
      for (int s = 0; s < N; ++s)
        for (int e = 0; e < N; ++e) DP[0][s][e] = min(DP[0][s][e], T[i][s][e]);
  }
  for (int i = 1; i <= N; ++i) {
    for (int s = 0; s < N; ++s)
      for (int e = 0; e < N; ++e) DP[i][s][e] = DP[i - 1][s][e];
    for (int m = 0; m < N; ++m)
      for (int s = 0; s < N; ++s)
        for (int e = 0; e < N; ++e)
          DP[i][s][e] = min(DP[i][s][e], DP[0][s][m] + DP[i - 1][m][e]);
  }
  for (int i = 0; i < R; ++i) {
    int x, y, k;
    scanf("%d %d %d", &x, &y, &k);
    if (k > N) k = N;
    printf("%d\n", DP[k][x - 1][y - 1]);
  }
  return 0;
}
