#include <bits/stdc++.h>
using namespace std;
int N, M, R;
int T[65][65][65], F[65][65][65], D[65][65];
int main() {
  scanf("%d%d%d", &N, &M, &R);
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++) F[i][j][0] = 0x3f3f3f3f;
  for (int t = 1; t <= M; t++) {
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= N; j++) scanf("%d", &D[i][j]);
    for (int k = 1; k <= N; k++)
      for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
          if (D[i][j] > D[i][k] + D[k][j]) D[i][j] = D[i][k] + D[k][j];
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= N; j++)
        if (D[i][j] < F[i][j][0]) F[i][j][0] = D[i][j];
  }
  for (int chg = 1; chg < N; chg++) {
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= N; j++) F[i][j][chg] = F[i][j][chg - 1];
    for (int k = 1; k <= N; k++)
      for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
          if (F[i][j][chg] > F[i][k][0] + F[k][j][chg - 1])
            F[i][j][chg] = F[i][k][0] + F[k][j][chg - 1];
  }
  while (R--) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    k = min(k, N - 1);
    printf("%d\n", F[s][t][k]);
  }
  return 0;
}
