#include <bits/stdc++.h>
using namespace std;
int g[61][61][61];
int d[61][61][61];
const int INF = 1e9 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, r;
  cin >> n >> m >> r;
  memset(d, INF, sizeof d);
  for (int car = 1; car <= m; car++) {
    for (int source = 1; source <= n; source++)
      for (int des = 1; des <= n; des++) cin >> g[car][source][des];
    for (int mid = 1; mid <= n; mid++)
      for (int source = 1; source <= n; source++)
        for (int des = 1; des <= n; des++) {
          g[car][source][des] =
              min(g[car][source][mid] + g[car][mid][des], g[car][source][des]);
        }
    for (int source = 1; source <= n; source++)
      for (int des = 1; des <= n; des++) {
        d[0][source][des] = min(d[0][source][des], g[car][source][des]);
      }
  }
  for (int ncar = 1; ncar <= n; ncar++)
    for (int mid = 1; mid <= n; mid++)
      for (int source = 1; source <= n; source++)
        for (int des = 1; des <= n; des++) {
          d[ncar][source][des] =
              min(d[ncar][source][des],
                  min(d[ncar - 1][source][mid] + d[0][mid][des],
                      d[0][source][mid] + d[ncar - 1][mid][des]));
        }
  while (r--) {
    int s, t, k;
    cin >> s >> t >> k;
    k = min(k, n);
    cout << d[k][s][t] << endl;
  }
}
