#include <bits/stdc++.h>
using namespace std;
const int N = 66, INF = 1 << 30;
int mat[N][N], f[N][N], opt[N][N][N];
void update(int n) {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], mat[i][j]);
}
int main() {
  int n, m, Q;
  while (scanf("%d%d%d", &n, &m, &Q) != -1) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) f[i][j] = INF;
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++) scanf("%d", &mat[j][k]);
      update(n);
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 0; k < n - 1; k++) opt[i][j][k] = k == 0 ? f[i][j] : INF;
    for (int k = 1; k <= n - 2; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          for (int which = 1; which <= n; which++)
            opt[i][j][k] =
                min(opt[i][j][k], opt[i][which][k - 1] + opt[which][j][0]);
    for (int i = 0; i < Q; i++) {
      int s, t, k;
      scanf("%d%d%d", &s, &t, &k);
      int res = INF;
      for (int j = 0; j <= min(k, n - 2); j++) res = min(res, opt[s][t][j]);
      printf("%d\n", res);
    }
  }
  return 0;
}
