#include <bits/stdc++.h>
using namespace std;
const int N = 65;
const long long M = 1e9 + 7;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int dp[N][N][N], g[N][N];
void solve() {
  int n, m, r;
  scanf("%d%d%d", &n, &m, &r);
  for (int k = 0; k <= n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) dp[k][i][j] = 1 << 29;
  while (m--) {
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < n; ++k) scanf("%d", &g[j][k]);
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
          dp[0][i][j] = min(dp[0][i][j], g[i][j]);
        }
      }
    }
  }
  for (int k = 1; k <= n; ++k)
    for (int a = 0; a < n; ++a)
      for (int b = 0; b < n; ++b)
        for (int c = 0; c < n; ++c)
          dp[k][b][c] = min(dp[k][b][c], dp[k - 1][b][a] + dp[0][a][c]);
  while (r--) {
    int u, v, k;
    scanf("%d%d%d", &u, &v, &k);
    k = min(k, n);
    --u, --v;
    printf("%d\n", dp[k][u][v]);
  }
}
int main() {
  int t = 1;
  for (int tt = 1; tt <= t; ++tt) {
    solve();
    puts("");
  }
}
