#include <bits/stdc++.h>
using namespace std;
const int N = 70 + 20, N2 = 1e4 + 10, MOD = 1e9 + 7, MAX_CHAR = 26;
int n, m, r, sp[N][N][N], sptemp[N][N];
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) sp[i][j][k] = 1e9;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        scanf("%d", &sptemp[j][k]);
      }
    }
    for (int mid = 0; mid < n; mid++) {
      for (int fr = 0; fr < n; fr++) {
        for (int to = 0; to < n; to++) {
          sptemp[fr][to] =
              min(sptemp[fr][mid] + sptemp[mid][to], sptemp[fr][to]);
          sp[fr][to][1] = min(sptemp[fr][to], sp[fr][to][1]);
        }
      }
    }
  }
  for (int kk = 2; kk < N; kk++) {
    for (int mm = 0; mm < n; mm++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          sp[i][j][kk] = min(sp[i][j][kk], sp[i][mm][kk - 1] + sp[mm][j][1]);
        }
      }
    }
  }
  while (r--) {
    int a, b, km;
    scanf("%d%d%d", &a, &b, &km);
    a--, b--, km++;
    km = min(60, km);
    printf("%d\n", sp[a][b][km]);
  }
  return 0;
}
