#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 60 + 5, mod = 1e9 + 7, inf = 1e12, maxq = 5e5 + 30,
                    maxm = 1e3 + 30;
const long double eps = 0.0000001;
long long int poww(long long int a, long long int b) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % mod, b / 2) % mod
                      : poww(a * a % mod, b / 2) % mod));
}
int mat[N][N][N];
int dp[maxm][N][N];
int d[N][N][N][N];
int n, m, r;
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(d, 63, sizeof d);
  cin >> n >> m >> r;
  for (int i = 1; i < m + 1; i++)
    for (int j = 1; j < n + 1; j++)
      for (int k = 1; k < n + 1; k++) cin >> mat[i][j][k];
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < n + 1; j++)
      for (int k = 1; k < m + 1; k++) d[0][i][j][k] = mat[k][i][j];
  for (int k = 1; k < n + 1; k++)
    for (int i = 1; i < n + 1; i++)
      for (int j = 1; j < n + 1; j++) {
        if (i != j) {
          for (int x = 1; x < m + 1; x++) {
            d[k][i][j][x] =
                min(d[k - 1][i][j][x], d[k - 1][i][k][x] + d[k - 1][k][j][x]);
          }
        }
      }
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < n + 1; j++) {
      if (i != j) {
        for (int k = 1; k < m + 1; k++) {
          if (k > 1) {
            if (dp[0][i][j] > d[n][i][j][k]) dp[0][i][j] = d[n][i][j][k];
          } else
            dp[0][i][j] = d[n][i][j][k];
        }
      } else
        dp[0][i][j] = 0;
    }
  for (int k = 1; k < 1001; k++) {
    for (int i = 1; i < n + 1; i++) {
      for (int j = 1; j < n + 1; j++) {
        dp[k][i][j] = dp[k - 1][i][j];
        if (i == j) continue;
        for (int y = 1; y < n + 1; y++)
          if (dp[k - 1][i][y] + dp[0][y][j] < dp[k][i][j])
            dp[k][i][j] = dp[k - 1][i][y] + dp[0][y][j];
      }
    }
  }
  int x, y, z;
  for (int i = 0; i < r; i++) {
    cin >> x >> y >> z;
    cout << dp[z][x][y] << '\n';
  }
  return 0;
}
