#include <bits/stdc++.h>
using namespace std;
int const MAXN = 60 + 10;
int w[MAXN][MAXN][MAXN];
int ans[MAXN][MAXN][1000 + 10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, r, s, t, k;
  cin >> n >> m >> r;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int l = 1; l <= n; l++) {
        cin >> w[i][j][l];
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int l = 1; l <= n; l++) {
        for (int c = 1; c <= n; c++) {
          w[i][l][c] = min(w[i][l][c], w[i][l][j] + w[i][j][c]);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans[0][i][j] = w[1][i][j];
      for (int l = 1; l <= m; l++) {
        ans[0][i][j] = min(ans[0][i][j], w[l][i][j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int l = 1; l <= n; l++) {
        ans[i][j][l] = ans[i - 1][j][l];
        for (int c = 1; c <= n; c++) {
          ans[i][j][l] = min(ans[i][j][l], ans[i - 1][j][c] + ans[0][c][l]);
        }
      }
    }
  }
  for (int i = 1; i <= r; i++) {
    cin >> s >> t >> k;
    if (k > n) k = n;
    cout << ans[k][s][t] << "\n";
  }
  return 0;
}
