#include <bits/stdc++.h>
using namespace std;
const int maxn = 70;
long long dp[1010][maxn][maxn];
long long g[maxn][maxn][maxn];
int n, m, r;
int main() {
  scanf("%d %d %d", &n, &m, &r);
  for (int cur = 0; cur < m; cur++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) scanf("%d", &g[cur][i][j]);
  memset(dp, 31, sizeof dp);
  for (int mac = 0; mac < m; mac++) {
    for (int lvl = 0; lvl < n; lvl++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          g[mac][i][j] = min(g[mac][i][j], g[mac][i][lvl] + g[mac][lvl][j]);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) dp[0][i][j] = min(dp[0][i][j], g[mac][i][j]);
  }
  for (int k = 1; k < 1003; k++)
    for (int lvl = 0; lvl < n; lvl++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          dp[k][i][j] = min(dp[k][i][j], dp[k - 1][i][lvl] + dp[0][lvl][j]);
  for (int i = 0, s, t, k; i < r; i++)
    scanf("%d %d %d", &s, &t, &k), s--, t--, printf("%d \n", dp[k][s][t]);
}
