#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60 + 2, MAXM = 60 + 2, MAXK = 60 + 2;
int n, m, r, si, ti, ki;
int Matrix[MAXM][MAXN][MAXN];
int dp[MAXM][MAXN][MAXN][MAXN];
int ans[MAXN][MAXN][MAXK];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> r;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int z = 1; z <= n; z++) {
        cin >> Matrix[i][j][z];
        dp[i][j][z][0] = Matrix[i][j][z];
      }
  for (int i = 1; i <= m; i++)
    for (int q = 1; q <= n; q++)
      for (int j = 1; j <= n; j++)
        for (int z = 1; z <= n; z++) {
          if (q == j || q == z) {
            dp[i][j][z][q] = dp[i][j][z][q - 1];
            continue;
          } else
            dp[i][j][z][q] = min(dp[i][j][q][q - 1] + dp[i][q][z][q - 1],
                                 dp[i][j][z][q - 1]);
        }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      ans[i][j][0] = 1e9;
      for (int q = 1; q <= m; q++)
        ans[i][j][0] = min(ans[i][j][0], dp[q][i][j][n]);
    }
  for (int k = 1; k <= 60; k++)
    for (int j = 1; j <= n; j++)
      for (int i = 1; i <= n; i++) {
        ans[i][j][k] = 1e9;
        for (int l = 1; l <= n; l++)
          ans[i][j][k] = min(ans[i][l][k - 1] + ans[l][j][0], ans[i][j][k]);
      }
  for (int i = 0; i < r; i++) {
    cin >> si >> ti >> ki;
    if (ki > n) ki = n;
    cout << ans[si][ti][ki] << '\n';
  }
}
