#include <bits/stdc++.h>
using namespace std;
const int maxn = 65;
const int inf = 1e9;
int n, m, r;
int dp[maxn][maxn][maxn];
int a[maxn][maxn][maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> r;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) cin >> a[i][j][k];
  for (int i = 0; i < n; 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 < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        for (int z = 0; z < n; z++) {
          a[i][k][z] = min(a[i][j][z] + a[i][k][j], a[i][k][z]);
          dp[0][k][z] = min(dp[0][k][z], a[i][k][z]);
        }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        for (int z = 0; z < n; z++)
          dp[i][k][z] = min(dp[i][k][z], dp[i - 1][k][j] + dp[0][j][z]);
      }
    }
  }
  for (int i = 0; i < r; i++) {
    int s, t, k;
    cin >> s >> t >> k;
    s--, t--;
    k = min(k, n - 2);
    cout << dp[k][s][t] << '\n';
  }
  return 0;
}
