#include <bits/stdc++.h>
using namespace std;
const int N = 62;
int dp[N][N][N], dis[N][N], tmp[N][N], n, m, q;
int main() {
  scanf("%d%d%d", &n, &m, &q);
  memset(dis, 0x3f, sizeof dis);
  for (int i = 1; i <= m; ++i) {
    for (int x = 1; x <= n; ++x)
      for (int y = 1; y <= n; ++y) scanf("%d", &tmp[x][y]);
    for (int z = 1; z <= n; ++z)
      for (int x = 1; x <= n; ++x)
        for (int y = 1; y <= n; ++y)
          if (tmp[x][z] + tmp[z][y] < tmp[x][y])
            tmp[x][y] = tmp[x][z] + tmp[z][y];
    for (int x = 1; x <= n; ++x)
      for (int y = 1; y <= n; ++y)
        if (tmp[x][y] < dis[x][y]) dis[x][y] = tmp[x][y];
  }
  memset(dp, 0x3f, sizeof dp);
  for (int x = 1; x <= n; ++x)
    for (int y = 1; y <= n; ++y) dp[0][x][y] = dis[x][y];
  for (int i = 1; i <= n; ++i)
    for (int x = 1; x <= n; ++x)
      for (int y = 1; y <= n; ++y)
        for (int z = 1; z <= n; ++z)
          dp[i][x][y] = min(dp[i][x][y], dp[i - 1][x][z] + dis[z][y]);
  for (int _ = 1; _ <= q; ++_) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    printf("%d\n", dp[min(k, n)][s][t]);
  }
  return 0;
}
