#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
const int inf = 2e9 + 7;
double eps = 1e-6;
const int mod = 998244353;
const int N = 62;
const double pi = acos(-1.0);
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long exgcd(long long a, long long b, long long& x, long long& y) {
  long long c;
  return !b ? (x = 1, y = 0, a)
            : (c = exgcd(b, a % b, y, x), y -= (a / b) * x, c);
}
long long INV(long long a) {
  long long x, y;
  exgcd(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}
int car[N][N][N];
int dp[N][N][N];
int main() {
  int n, m, r;
  cin >> n >> m >> r;
  const int up = 61;
  for (int i = 0; i <= up; ++i)
    for (int j = 0; j <= n; ++j)
      for (int k = 0; k <= n; ++k)
        if (j != k) dp[i][j][k] = 1e9;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k) car[i][j][k] = read();
    for (int c = 1; c <= n; ++c)
      for (int j = 1; j <= n; ++j)
        for (int k = 1; k <= n; ++k)
          car[i][j][k] = min(car[i][j][k], car[i][j][c] + car[i][c][k]);
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k) dp[1][j][k] = min(dp[1][j][k], car[i][j][k]);
  }
  for (int i = 2; i <= up; ++i)
    for (int x = 1; x <= n; ++x)
      for (int y = 1; y <= n; ++y)
        for (int c = 1; c <= n; ++c) {
          dp[i][x][y] = min({dp[i][x][y], dp[i - 1][x][c] + dp[1][c][y],
                             dp[1][x][c] + dp[i - 1][c][y]});
        }
  while (r--) {
    int s = read(), t = read(), k = read();
    k++;
    k = min(k, up);
    cout << dp[k][s][t] << '\n';
  }
}
