#include <bits/stdc++.h>
long long f[70][70];
long long d[70][70][70];
int main(void) {
  int n, m, r;
  scanf("%i %i %i", &n, &m, &r);
  int i, j, k, l;
  memset(d, 60, sizeof(d));
  for (l = 1; l <= m; l++) {
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) scanf("%lld", &f[i][j]);
    for (k = 1; k <= n; k++)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++) {
          f[i][j] = (f[i][j] < f[i][k] + f[k][j] ? f[i][j] : f[i][k] + f[k][j]);
          d[i][j][0] = (d[i][j][0] < f[i][j] ? d[i][j][0] : f[i][j]);
        }
  }
  for (l = 1; l <= n; l++)
    for (k = 1; k <= n; k++)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++) {
          d[i][j][l] =
              (d[i][j][l] < d[i][j][l - 1] ? d[i][j][l] : d[i][j][l - 1]);
          d[i][j][l] = (d[i][j][l] < d[i][k][0] + d[k][j][l - 1]
                            ? d[i][j][l]
                            : d[i][k][0] + d[k][j][l - 1]);
        }
  while (r--) {
    int s, e, k;
    scanf("%i %i %i", &s, &e, &k);
    printf("%lld\n", d[s][e][(k < n ? k : n)]);
  }
  return 0;
}
