#include <bits/stdc++.h>
using namespace std;
int n, m, r, f[1009][61][61], cost[62][62][62];
int main() {
  cin >> n >> m >> r;
  for (long long i = 1; i <= m; i++)
    for (long long j = 1; j <= n; j++)
      for (long long k = 1; k <= n; k++) scanf("%d", &cost[i][j][k]);
  for (long long i = 1; i <= m; i++)
    for (long long k = 1; k <= n; k++)
      for (long long u = 1; u <= n; u++)
        for (long long v = 1; v <= n; v++)
          cost[i][u][v] = min(cost[i][u][v], cost[i][u][k] + cost[i][k][v]);
  for (long long i = 0; i <= n; i++)
    for (long long j = 1; j <= n; j++)
      for (long long k = 1; k <= n; k++) f[i][j][k] = 0x7fffffff / 2;
  for (long long k = 1; k <= m; k++)
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= n; j++)
        for (long long w = 1; w <= n; w++)
          f[0][i][j] = min(f[0][i][j], cost[k][i][w] + cost[k][w][j]);
  for (long long i = 1; i <= n; i++)
    for (long long w = 1; w <= n; w++)
      for (long long j = 1; j <= n; j++)
        for (long long k = 1; k <= n; k++)
          f[i][j][k] = min(f[i][j][k], f[i - 1][j][w] + f[0][w][k]);
  while (r--) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    w = min(w, n);
    int ret = 0x7fffffff / 2;
    for (long long i = 0; i <= w; i++) ret = min(ret, f[i][u][v]);
    printf("%d\n", ret);
  }
  return 0;
}
