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