#include <bits/stdc++.h>
const int N = 69;
const int inf = 0x3f3f3f3f;
using namespace std;
int n, m, r;
bool vis[N][N];
int d[N][N][N], dis[N][N][N];
void floyd(int dis[N][N]) {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  return;
}
int dp[N][N][N];
int main() {
  while (scanf("%d%d%d", &n, &m, &r) == 3) {
    for (int k = 1; k <= m; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) scanf("%d", &dis[k][i][j]);
    for (int i = 1; i <= m; i++) floyd(dis[i]);
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= m; k++)
          dp[i][j][0] = min(dis[k][i][j], dp[i][j][0]);
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          for (int l = 1; l <= n; l++)
            dp[i][j][k] = min(dp[i][j][k], dp[i][l][k - 1] + dp[l][j][0]);
    }
    for (int i = 0; i < r; i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      int ret = inf;
      if (c > n) c = n;
      for (int k = 0; k <= c; k++) ret = min(ret, dp[a][b][k]);
      printf("%d\n", ret);
    }
  }
  return 0;
}
