#include <bits/stdc++.h>
using namespace std;
const int maxn = 61, inf = 2e9;
int dis[maxn][maxn][maxn], dp[maxn][maxn][maxn], D[maxn][maxn];
int main() {
  ios::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) cin >> dis[i][j][k];
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < maxn; j++)
      for (int k = 0; k < maxn; k++) {
        D[i][j] = inf;
        dp[i][j][k] = inf;
      }
  for (int c = 1; c <= m; c++)
    for (int u = 1; u <= n; u++)
      for (int l = 1; l <= n; l++)
        for (int r = 1; r <= n; D[l][r] = min(D[l][r], dis[c][l][r]), r++)
          dis[c][l][r] = min(dis[c][l][r], dis[c][l][u] + dis[c][u][r]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dp[i][j][0] = min(dp[i][j][0], D[i][j]);
  for (int k = 1; k < n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int u = 1; u <= n; u++)
          dp[i][j][k] = min(dp[i][j][k], dp[i][u][k - 1] + D[u][j]);
  while (q--) {
    int st, en, k;
    cin >> st >> en >> k;
    k = min(n - 1, k);
    cout << dp[st][en][k] << "\n";
  }
  return 0;
}
