#include <bits/stdc++.h>
using namespace std;
const int N = 60, M = 70;
long long n, A[M][M][M], dp[M][M][M], m, k, r;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m >> r;
  memset(dp, 63, sizeof dp);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) cin >> A[j][k][i];
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        for (int k1 = 1; k1 <= n; k1++)
          A[k][k1][i] = min(A[k][k1][i], A[k][j][i] + A[j][k1][i]);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= m; k++) dp[i][j][0] = min(A[i][j][k], dp[i][j][0]);
  for (int i = 1; i <= N; i++)
    for (int k1 = 1; k1 <= n; k1++)
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++)
          dp[j][k][i] = min(dp[j][k1][i - 1] + dp[k1][k][0],
                            min(dp[j][k][i], dp[j][k][i - 1]));
  for (int i = 0; i < r; i++) {
    int s, t, k;
    cin >> s >> t >> k;
    cout << dp[s][t][min(k, 60)] << endl;
  }
}
