#include <bits/stdc++.h>
using namespace std;
char BUFFER[100000 + 5];
bool readn(int &n) { return scanf("%d", &n) == 1; }
bool readl(long long &n) { return scanf("%I64d", &n) == 1; }
bool readd(double &n) { return scanf("%lf", &n) == 1; }
bool reads(string &s) {
  s = "";
  int n = scanf("%s", BUFFER);
  if (n == 1) s = BUFFER;
  return n == 1;
}
bool readln(string &s) {
  char *valid = gets(BUFFER);
  if (valid) s = BUFFER;
  return ((bool)valid);
}
void Print(long long &n, bool printNewLine = true) {
  printNewLine ? printf("%I64d\n", n) : printf("%I64d", n);
}
const int maxn = 65;
int graph[maxn][maxn][maxn], dp[maxn][maxn][maxn], cost[maxn][maxn];
void init(int n, int m) {
  int i, j, k, t;
  for (i = 0; i < n; ++i)
    for (j = 0; j < n; ++j) cost[i][j] = 1e9 + 10;
  for (k = 0; k < m; ++k)
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j) readn(graph[k][i][j]);
  for (t = 0; t < m; ++t)
    for (k = 0; k < n; ++k)
      for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
          if (graph[t][i][k] + graph[t][k][j] < graph[t][i][j])
            graph[t][i][j] = graph[t][i][k] + graph[t][k][j];
  for (t = 0; t < m; ++t)
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j) cost[i][j] = min(cost[i][j], graph[t][i][j]);
  for (t = 0; t < maxn; ++t)
    for (i = 0; i < maxn; ++i)
      for (j = 0; j < maxn; ++j) dp[i][j][t] = 1e9 + 10;
  for (t = 0; t < maxn; ++t)
    for (i = 0; i < maxn; ++i) dp[i][i][t] = 0;
  for (t = 0; t < n + 1; ++t)
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j) {
        for (k = 0; k < n; ++k) {
          dp[i][k][t + 1] = min(dp[i][k][t + 1], dp[i][j][t] + cost[j][k]);
        }
      }
}
int main() {
  int n, m, k, q, a, b;
  cin >> n >> m >> q;
  init(n, m);
  while (q--) {
    readn(a);
    readn(b);
    readn(k);
    a--;
    b--;
    k = min(k, n - 1);
    k++;
    printf("%d\n", dp[a][b][k]);
  }
  return 0;
}
