#include <bits/stdc++.h>
int map[65][65][65];
int sh[65][65];
int dp[65][65][65];
void floyd(int n, int t) {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        if (map[t][j][k] > map[t][j][i] + map[t][i][k])
          map[t][j][k] = map[t][j][i] + map[t][i][k];
      }
    }
  }
}
int min(int a, int b) { return a < b ? a : b; }
int dfs(int s, int t, int limit, int n) {
  if (dp[s][t][limit] != 2100000000) return dp[s][t][limit];
  int i;
  for (i = 1; i <= n; i++) {
    dp[s][t][limit] = min(dp[s][t][limit], dfs(s, i, limit - 1, n) + sh[i][t]);
  }
  return dp[s][t][limit];
}
int main() {
  int n, m, r, i, j, k;
  scanf("%d%d%d", &n, &m, &r);
  for (k = 1; k <= m; k++) {
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        scanf("%d", &map[k][i][j]);
      }
    }
    floyd(n, k);
  }
  memset(sh, 1, sizeof(sh));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= m; k++) {
        sh[i][j] = min(sh[i][j], map[k][i][j]);
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dp[i][j][0] = sh[i][j];
      for (k = 1; k <= 1000; k++) dp[i][j][k] = 2100000000;
    }
  }
  int x, y;
  for (i = 0; i < r; i++) {
    scanf("%d%d%d", &x, &y, &k);
    if (k <= 60)
      printf("%d\n", dfs(x, y, k, n));
    else
      printf("%d\n", dfs(x, y, 60, n));
  }
  return 0;
}
