#include <bits/stdc++.h>
using namespace std;
int DP[1001][61][61], D[61][61][61];
int N, M, R;
int main() {
  cin >> N >> M >> R;
  for (int m = 0; m < M; m++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) cin >> D[m][i][j];
  for (int m = 0; m < M; m++)
    for (int k = 0; k < N; k++)
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          D[m][i][j] = min(D[m][i][j], D[m][i][k] + D[m][k][j]);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      DP[0][i][j] = 999999999;
      for (int m = 0; m < M; m++) DP[0][i][j] = min(DP[0][i][j], D[m][i][j]);
    }
  for (int k = 1; k <= 1000; k++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) {
        DP[k][i][j] = 999999999;
        for (int p = 0; p < N; p++)
          DP[k][i][j] = min(DP[k][i][j], DP[k - 1][i][p] + DP[0][p][j]);
      }
  for (int i = 0; i < R; i++) {
    int a, b, k;
    cin >> a >> b >> k;
    cout << DP[k][a - 1][b - 1] << "\n";
  }
}
