#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 2147483640;
const long long i64_inf = 9223372036854775800ll;
const double pi = acos(-1.0);
using namespace std;
int d[61][61][61];
int dest[61][61][61];
int n, m, r;
int main() {
  cin >> n >> m >> r;
  for (int k = 0; k <= n; k++)
    for (int v1 = 0; v1 < n; v1++)
      for (int v2 = 0; v2 < n; v2++) d[v1][v2][k] = int_inf * (v1 != v2);
  for (int t = 0; t < (int)m; t++)
    for (int i = 0; i < (int)n; i++)
      for (int j = 0; j < (int)n; j++) scanf("%d", &dest[t][i][j]);
  for (int t = 0; t < (int)m; t++)
    for (int v = 0; v < (int)n; v++)
      for (int v1 = 0; v1 < (int)n; v1++)
        for (int v2 = 0; v2 < (int)n; v2++)
          dest[t][v1][v2] =
              min(dest[t][v1][v2], dest[t][v1][v] + dest[t][v][v2]),
          d[v1][v2][0] = min(d[v1][v2][0], dest[t][v1][v2]);
  for (int k = 1; k < (int)n + 1; k++)
    for (int v = 0; v < (int)n; v++)
      for (int v1 = 0; v1 < (int)n; v1++)
        for (int v2 = 0; v2 < (int)n; v2++)
          d[v1][v2][k] = min(d[v1][v2][k], d[v1][v][k - 1] + d[v][v2][0]);
  for (int v1 = 0; v1 < (int)n; v1++)
    for (int v2 = 0; v2 < (int)n; v2++) {
      int mi = d[v1][v2][0];
      for (int k = 1; k < (int)n + 1; k++)
        d[v1][v2][k] = min(d[v1][v2][k], mi), mi = min(mi, d[v1][v2][k]);
    }
  for (int i = 0; i < (int)r; i++) {
    int v1, v2, k;
    scanf("%d%d%d", &v1, &v2, &k);
    v1--;
    v2--;
    k = min(k, n);
    printf("%d\n", d[v1][v2][k]);
  }
  return 0;
}
