#include <bits/stdc++.h>
const long long inf = LLONG_MAX;
const long long mod = 1000000000;
const double PI = 3.14159265358979323846;
const long long N = 1e6 + 6;
const long long M = 3e5 + 5;
using namespace std;
long long n, m, r;
long long d[61][61][61];
long long ans[61][61][61];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc;
  tc = 1;
  while (tc--) {
    cin >> n >> m >> r;
    for (long long k = 1; k <= m; k++) {
      for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= n; j++) cin >> d[k][i][j];
      }
    }
    for (long long car = 1; car <= m; car++) {
      for (long long k = 1; k <= n; k++) {
        for (long long i = 1; i <= n; i++) {
          for (long long j = 1; j <= n; j++) {
            d[car][i][j] = min(d[car][i][j], d[car][i][k] + d[car][k][j]);
          }
        }
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; j++) {
        ans[0][i][j] = inf;
        for (long long car = 1; car <= m; car++) {
          ans[0][i][j] = min(ans[0][i][j], d[car][i][j]);
        }
      }
    }
    for (long long k = 1; k <= n; k++) {
      for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= n; j++) {
          ans[k][i][j] = inf;
          for (long long midcity = 1; midcity <= n; midcity++) {
            ans[k][i][j] =
                min(ans[k][i][j], ans[k - 1][i][midcity] + ans[0][midcity][j]);
          }
        }
      }
    }
    while (r--) {
      long long s, t, k;
      cin >> s >> t >> k;
      k = min(n, k);
      cout << ans[k][s][t] << "\n";
    }
  }
}
