#include <bits/stdc++.h>
using namespace std;
const int MAXN = 62;
int n, m, r;
int mat[MAXN][MAXN][MAXN];
int dp[MAXN][MAXN][MAXN];
void floyd(int x) {
  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        mat[x][i][j] = min(mat[x][i][j], mat[x][i][k] + mat[x][k][j]);
}
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < n; ++k) scanf("%d", &mat[i][j][k]);
  for (int i = 0; i < m; ++i) floyd(i);
  memset(dp, 20, sizeof(dp));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < m; ++k) dp[i][j][0] = min(dp[i][j][0], mat[k][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 s = 0; s < n; ++s)
          dp[i][j][k] = min(dp[i][j][k], dp[i][s][k - 1] + dp[s][j][0]);
  for (int i = 0, a, b, c; i < r; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    int res = ~0U >> 1;
    for (int j = 0; j <= min(n, c); ++j) res = min(res, dp[a][b][j]);
    printf("%d\n", res);
  }
  return 0;
}
