#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MAX = 1e9 + 5;
int i, j, k, n, m, x, y, r;
int SP[61][61][61];
int SP2[61][61];
int dp[61][61][61];
int f(int a, int b, int left) {
  if (a == b) return 0;
  if (left < 0) return 1000000000 + 5;
  int &r = dp[a][b][left];
  if (r != -1) return r;
  r = 1000000000 + 5;
  for (int i = 1; i <= n; i++) r = min(r, f(i, b, left - 1) + SP2[a][i]);
  return r;
}
int main() {
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= 60; i++)
    for (int j = 1; j <= 60; j++) SP2[i][j] = 1000000000;
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) {
        scanf("%d", &SP[i][j][k]);
        SP2[j][k] = min(SP[i][j][k], SP2[j][k]);
      }
  for (int w = 1; w <= m; w++)
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          SP[w][i][j] = min(SP[w][i][j], SP[w][i][k] + SP[w][k][j]);
  for (int w = 1; w <= m; w++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) SP2[i][j] = min(SP2[i][j], SP[w][i][j]);
  for (int i = 1; i <= r; i++) {
    scanf("%d %d %d", &x, &y, &k);
    printf("%d\n", f(x, y, min(k, n)));
  }
  return 0;
}
