#include <bits/stdc++.h>
using namespace std;
int dp[80][80][80], d[80][80][80];
int n, m, r;
void prepare() {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        for (int h = 1; h <= n; h++)
          d[i][k][h] = min(d[i][k][h], d[i][k][j] + d[i][j][h]);
  }
  int tem;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      tem = 1e7;
      for (int k = 1; k <= m; k++) tem = min(tem, d[k][i][j]);
      dp[0][i][j] = tem;
    }
}
void work() {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) dp[k][i][j] = 1e7;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int h = 1; h <= n; h++)
          dp[k][i][j] = min(dp[k][i][j], dp[k - 1][i][h] + dp[0][h][j]);
  }
}
int main() {
  int a, b, c;
  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", &d[i][j][k]);
  }
  prepare();
  work();
  for (int i = 1; i <= r; i++) {
    scanf("%d%d%d", &a, &b, &c);
    if (c > n) c = n;
    printf("%d\n", dp[c][a][b]);
  }
}
