#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 62, maxn = 1000 + 2, INF = 1e9;
int a[MAXN][MAXN][MAXN];
int dp[MAXN][MAXN][maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int t = 0; t < n; ++t) {
        cin >> a[i][j][t];
      }
    }
  }
  for (int c = 0; c < m; ++c) {
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          a[c][i][j] = min(a[c][i][j], a[c][i][k] + a[c][k][j]);
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j][1] = a[0][i][j];
      for (int k = 0; k < m; ++k) {
        dp[i][j][1] = min(dp[i][j][1], a[k][i][j]);
      }
    }
  }
  for (int k = 2; k <= n + 1; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        dp[i][j][k] = dp[i][j][k - 1];
        for (int t = 0; t < n; ++t) {
          dp[i][j][k] = min(dp[i][j][k], dp[i][t][1] + dp[t][j][k - 1]);
        }
      }
    }
  }
  for (int i = 0; i < r; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    cout << dp[a - 1][b - 1][min(c, n) + 1] << endl;
  }
}
