#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 7;
const int N = 62;
const int R = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int n, m, r, c[N][N];
int dp[N][N][N];
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) dp[i][j][0] = INF;
  for (int _m = (0); _m < (m); ++_m) {
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j) scanf("%d", &c[i][j]);
    for (int k = (0); k < (n); ++k)
      for (int i = (0); i < (n); ++i)
        for (int j = (0); j < (n); ++j)
          c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j) dp[i][j][0] = min(dp[i][j][0], c[i][j]);
  }
  for (int t = (1); t < (n + 1); ++t) {
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j) dp[i][j][t] = dp[i][j][t - 1];
    for (int k = (0); k < (n); ++k)
      for (int i = (0); i < (n); ++i)
        for (int j = (0); j < (n); ++j)
          dp[i][j][t] = min(dp[i][j][t], dp[i][k][t - 1] + dp[k][j][0]);
  }
  for (int _r = (0); _r < (r); ++_r) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    --s, --t, k = min(k, n);
    printf("%d\n", dp[s][t][k]);
  }
  return 0;
}
