#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int Dist[60][60][60];
int G[60][60];
int DP[60][60][60];
int main() {
  int N, M, Q;
  cin >> 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", &Dist[i][j][k]);
  for (int Car = 0; Car < M; Car++)
    for (int k = 0; k < N; k++)
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          Dist[Car][i][j] =
              min(Dist[Car][i][j], Dist[Car][i][k] + Dist[Car][k][j]);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) G[i][j] = inf;
  for (int i = 0; i < 60; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) DP[i][j][k] = inf;
  for (int Car = 0; Car < M; Car++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) G[i][j] = min(G[i][j], Dist[Car][i][j]);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) DP[0][i][j] = G[i][j];
  for (int R = 1; R < 60; R++)
    for (int k = 0; k < N; k++)
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          DP[R][i][j] = min(DP[R][i][j], DP[R - 1][i][k] + G[k][j]);
  for (int i = 0; i < Q; i++) {
    int X, Y, Z;
    scanf("%d%d%d", &X, &Y, &Z);
    X--;
    Y--;
    if (Z >= 60) Z = 59;
    printf("%d\n", DP[Z][X][Y]);
  }
  return 0;
}
