#include <bits/stdc++.h>
using namespace std;
const int N = 70, M = 1e3 + 1, INF = 2 * 1e9;
int dp[N][N][M], a[N][N][N];
int mn[N][N], adj[N][N][N];
int main() {
  int n, m, r;
  scanf("%d%d%d", &n, &m, &r);
  for (int it = 0; it < m; it++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        scanf("%d", &a[i][j][it]);
        mn[i][j] = INF;
      }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) mn[i][j] = INF;
  for (int it = 0; it < m; it++)
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          a[i][j][it] = min(a[i][j][it], a[i][k][it] + a[k][j][it]);
  for (int k = 0; k < m; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) mn[i][j] = min(mn[i][j], a[i][j][k]);
  for (int k = 0; k < M; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) dp[i][j][k] = INF;
  for (int k = 0; k < M; k++)
    for (int i = 0; i < n; i++) dp[i][i][k] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dp[i][j][0] = mn[i][j];
  for (int k = 1; k < N; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int l = 0; l < n; l++)
          dp[i][j][k] = min(dp[i][j][k], mn[i][l] + dp[l][j][k - 1]);
  for (int i = 0; i < r; i++) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    s--;
    t--;
    k = min(k, n);
    printf("%d\n", dp[s][t][k]);
  }
}
