#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.14159265359;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long N = 60 + 10;
const long long INF = 1e18;
long long n, m, v, u, w, r, ans[N], dis[N][N][N], adj[N][N][N],
    dp[N][N][1000 + 10], dp1[N][N][1000 + 10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> r;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        cin >> dp[i][j][k];
      }
    }
  }
  for (int car = 1; car <= m; car++) {
    for (int k = 1; k <= n; k++) {
      for (int nodes = 1; nodes <= n; nodes++) {
        for (int nodef = 1; nodef <= n; nodef++) {
          dp[car][nodes][nodef] =
              min(dp[car][nodes][nodef], dp[car][nodes][k] + dp[car][k][nodef]);
        }
      }
    }
  }
  memset(dp1, 63, sizeof dp1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int car = 1; car <= m; car++) {
        dp1[i][j][0] = min(dp1[i][j][0], dp[car][i][j]);
      }
    }
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dp1[i][j][k] = dp1[i][j][k - 1];
        for (int v = 1; v <= n; v++) {
          dp1[i][j][k] = min(dp1[i][j][k], dp1[i][v][k - 1] + dp1[v][j][0]);
        }
      }
    }
  }
  long long s, f, k;
  while (r--) {
    cin >> s >> f >> k;
    cout << dp1[s][f][min(n, k)] << '\n';
  }
  return 0;
}
