#include <bits/stdc++.h>
using namespace std;
const int maxn = 60 + 10;
const long long oo = 1ll << 50;
long long mat[maxn][maxn][maxn];
long long dp[maxn][maxn][maxn];
int N, M, R;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M >> R;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) cin >> mat[i][j][k];
  for (int l = 0; l < M; l++)
    for (int k = 0; k < N; k++)
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          if (mat[l][i][k] + mat[l][k][j] < mat[l][i][j]) {
            mat[l][i][j] = mat[l][i][k] + mat[l][k][j];
          }
  for (int r = 0; r < N + 1; r++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) dp[r][i][j] = oo;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < M; k++) dp[0][i][j] = min(dp[0][i][j], mat[k][i][j]);
    }
  for (int r = 1; r < N + 1; r++) {
    for (int k = 0; k < N; k++)
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++) {
          if (dp[r - 1][i][k] + dp[0][k][j] < dp[r][i][j]) {
            dp[r][i][j] = dp[r - 1][i][k] + dp[0][k][j];
          }
        }
  }
  while (R--) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    c = min(c, N);
    cout << dp[c][u][v] << '\n';
  }
  return 0;
}
