#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9 + 7;
const int N = int(1e5 + 7);
int n, m, q, a[60][60][60], d[60][60][60];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) d[i][j][k] = INF;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) scanf("%d", &a[i][j][k]);
    for (int r = 0; r < n; r++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          a[i][j][k] = min(a[i][j][k], a[i][j][r] + a[i][r][k]);
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) d[0][j][k] = min(d[0][j][k], a[i][j][k]);
  }
  for (int i = 1; i < n; i++)
    for (int r = 0; r < n; r++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          d[i][j][k] = min(d[i][j][k], d[i - 1][j][r] + d[0][r][k]);
  for (int i = 0; i < q; i++) {
    int second, t, k, res = INF;
    scanf("%d%d%d", &second, &t, &k);
    second--, t--;
    for (int j = 0; j <= min(k, n - 1); j++) res = min(res, d[j][second][t]);
    printf("%d\n", res);
  }
  return 0;
}
