#include <bits/stdc++.h>
using namespace std;
const int N = 63;
const int K = 1005;
const int INF = 1e9 + 20;
int cars[N][N][N];
int mn[N][N];
int dp[N][N][K];
int n, m, r;
int solve(int cur, int target, int k) {
  if (cur == target) return 0;
  if (k < 0) return INF;
  int &ret = dp[cur][target][k];
  if (~ret) return ret;
  ret = INF;
  for (int i = 0; i < int(n); i++)
    ret = min(ret, solve(i, target, k - 1) + mn[cur][i]);
  return ret;
}
void second(int &v) {
  v = 0;
  int p = 1;
  char c = 0;
  while (c < '0' || c > '9') {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = (v << 3) + (v << 1) + c - '0';
    c = getchar();
  }
  v *= p;
}
int main() {
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 0; i < int(m); i++)
    for (int j = 0; j < int(n); j++)
      for (int k = 0; k < int(n); k++) second(cars[i][j][k]);
  for (int a = 0; a < int(m); a++)
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(n); j++)
        for (int k = 0; k < int(n); k++)
          cars[a][j][k] = min(cars[a][j][k], cars[a][j][i] + cars[a][i][k]);
  for (int i = 0; i < int(n); i++)
    for (int j = 0; j < int(n); j++) mn[i][j] = cars[0][i][j];
  for (int a = 0; a < int(m); a++)
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(n); j++) mn[i][j] = min(mn[i][j], cars[a][i][j]);
  int s, t, k;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < int(r); i++) {
    second(s), second(t), second(k);
    s--, t--;
    printf("%d\n", solve(s, t, min(k, n + 1)));
  }
  return 0;
}
