#include <bits/stdc++.h>
using namespace std;
int n, i, j, m, r, k, t, s;
int a[61][61], b[61][61];
int dp[61][61][63];
int rec(int i, int j, int k) {
  if (i == j) {
    return 0;
  }
  if (k == 0) return 1e9;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int ans = b[i][j];
  int p;
  for (p = 1; p <= n; p++) {
    ans = min(ans, b[i][p] + rec(p, j, k - 1));
  }
  dp[i][j][k] = ans;
  return ans;
}
int main() {
  cout.setf(ios ::fixed | ios ::showpoint);
  cout.precision(9);
  cin >> n >> m >> r;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) b[i][j] = 1e9;
  for (t = 1; t <= m; t++) {
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) scanf("%d", &a[i][j]);
    for (k = 1; k <= n; k++)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++) a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) b[i][j] = min(b[i][j], a[i][j]);
  }
  memset(dp, -1, sizeof(dp));
  for (i = 1; i <= r; i++) {
    scanf("%d%d%d", &s, &t, &k);
    k = min(k, n);
    printf("%d\n", rec(s, t, k + 1));
  }
  return 0;
}
