#include <bits/stdc++.h>
using namespace std;
int n, m, r;
int car[65][65][65];
int dp[65][65][65];
void input() {
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) scanf("%d", &car[i][j][k]);
}
void dfs(int c) {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        car[c][i][j] = min(car[c][i][j], car[c][i][k] + car[c][k][j]);
}
void compute() {
  for (int i = 0; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) dp[i][j][k] = 1e9;
  for (int i = 1; i <= m; i++) dfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      for (int c = 1; c <= m; c++) dp[0][i][j] = min(dp[0][i][j], car[c][i][j]);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) {
        for (int h = 1; h <= n; h++)
          dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][h] + dp[0][h][k]);
      }
}
int main() {
  cin >> n >> m >> r;
  input();
  compute();
  int s, t, k;
  for (int i = 0; i < r; i++) {
    scanf("%d %d %d", &s, &t, &k);
    if (k > n) k = n;
    printf("%d\n", dp[k][s][t]);
  }
  return 0;
}
