#include <bits/stdc++.h>
using namespace std;
long long a[65][65][65][65], ans[65][65][65];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 1; i <= m; i++)
    for (int k = 1; k <= n; k++)
      for (int l = 1; l <= n; l++) cin >> a[i][0][k][l];
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        for (int l = 1; l <= n; l++)
          a[i][j][k][l] =
              min(a[i][j - 1][k][l], a[i][j - 1][k][j] + a[i][j - 1][j][l]);
  for (int j = 1; j <= n; j++)
    for (int k = 1; k <= n; k++) {
      ans[0][j][k] = a[1][n][j][k];
      for (int i = 2; i <= m; i++)
        ans[0][j][k] = min(ans[0][j][k], a[i][n][j][k]);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) {
        ans[i][j][k] = ans[i - 1][j][k];
        for (int l = 1; l <= n; l++)
          ans[i][j][k] = min(ans[i][j][k], ans[i - 1][j][l] + ans[0][l][k]);
      }
  for (int i = 1; i <= r; i++) {
    int s, t, k;
    cin >> s >> t >> k;
    cout << ans[min(k, n)][s][t] << '\n';
  }
  return 0;
}
