#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, m, q;
int dp[1005][65][65];
int w[65][65];
int road[65][65][65];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) w[i][j] = INF;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) scanf("%d", &road[i][j][k]);
  for (int f = 0; f < m; f++)
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          road[f][i][j] = min(road[f][i][j], road[f][i][k] + road[f][k][j]);
  for (int f = 0; f < m; f++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) w[i][j] = min(road[f][i][j], w[i][j]);
  for (int i = 0; i <= 1002; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) dp[i][j][k] = INF;
  for (int i = 0; i < n; i++) dp[0][i][i] = 0;
  for (int k = 1; k <= 1002; k++)
    for (int i = 0; i < n; i++)
      for (int l = 0; l < n; l++)
        for (int j = 0; j < n; j++)
          dp[k][l][j] = min(dp[k][l][j], dp[k - 1][l][i] + w[i][j]);
  for (int i = 0; i < q; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--;
    y--;
    z++;
    printf("%d\n", dp[z][x][y]);
  }
  return 0;
}
