#include <bits/stdc++.h>
using namespace std;
const int N = 65;
int data[N][N][N];
int dp[N][N][N];
int main() {
  int n, m, r;
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < m; i++) {
    for (int k = 0; k < n; k++)
      for (int j = 0; j < n; j++) scanf("%d", &data[i][k][j]);
    for (int p = 0; p < n; p++)
      for (int q = 0; q < n; q++)
        for (int j = 0; j < n; j++)
          data[i][q][j] = min(data[i][q][j], data[i][q][p] + data[i][p][j]);
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) {
        dp[0][j][k] = min(dp[0][j][k], data[i][j][k]);
      }
  for (int i = 1; i <= n; i++)
    for (int k = 0; k < n; k++)
      for (int p = 0; p < n; p++)
        for (int q = 0; q < n; q++)
          dp[i][k][p] = min(dp[i][k][p], dp[i - 1][k][q] + dp[0][q][p]);
  for (int i = 0; i < r; i++) {
    int u, v, s;
    scanf("%d%d%d", &u, &v, &s);
    printf("%d\n", dp[min(s, n)][--u][--v]);
  }
  return 0;
}
