#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int dp[1005][N][N], t[N][N][N], n, m, r;
int main() {
  std::ios::sync_with_stdio(false);
  for (int i = 0; i < 1002; i++)
    for (int j = 0; j < 100; j++)
      for (int k = 0; k < 100; k++) dp[i][j][k] = 1e8;
  cin >> n >> m >> r;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) cin >> t[i][j][k];
  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++)
          t[l][i][j] = min(t[l][i][j], t[l][i][k] + t[l][k][j]),
          dp[0][i][j] = min(dp[0][i][j], t[l][i][j]);
  for (int l = 1; l <= 1000; l++)
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          dp[l][i][j] = min(dp[l][i][j], dp[l - 1][i][k] + dp[0][k][j]);
  while (r--) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    cout << dp[c][a][b] << endl;
  }
  return 0;
}
