#include <bits/stdc++.h>
using namespace std;
const int MAXN = 70, INF = 1e+9;
int d[MAXN][MAXN][MAXN], dp[MAXN][MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  for (int l = 0; l < m; l++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) cin >> d[i][j][l];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < MAXN; k++) dp[i][j][k] = INF;
  for (int l = 0; l < m; l++)
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          d[i][j][l] = min(d[i][j][l], d[i][k][l] + d[k][j][l]);
  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], d[i][j][k]);
  for (int k = 1; k < MAXN; 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], dp[i][l][k - 1] + dp[l][j][0]);
  for (int i = 0, x, y, z; i < r; i++) {
    cin >> x >> y >> z;
    z = min(z, n - 1);
    cout << dp[x - 1][y - 1][z] << endl;
  }
  return 0;
}
