#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T multimod(T a, T b, T m) {
  T ans = 0ll;
  a %= m, b %= m;
  while (b) {
    if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m);
    b >>= 1ll;
    a = (m - a) > a ? a + a : a + a - m;
  }
  return (T)ans;
}
void sc(int &a) { scanf("%d", &a); }
void sc(long long &a) { scanf("%lld", &a); }
void sc(double &a) { scanf("%lf", &a); }
void sc(int &a, int &b) { scanf("%d %d", &a, &b); }
void sc(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void sc(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
void sc(int &a, int &b, long long &c) { scanf("%d %d %lld", &a, &b, &c); }
void sc(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void sc(string &str) { cin >> str; }
void sc(char *(str)) { scanf(" %s", str); }
void sc(char &c) { scanf(" %c", &c); }
int dis[(60 + 7)][(60 + 7)];
int arr[(60 + 7)][(60 + 7)][(60 + 7)];
int dp[(60 + 7)][(60 + 7)][(60 + 7)];
int n, m;
int solve(int s, int t, int rest) {
  int &ret = dp[s][t][rest];
  if (ret != -1) return ret;
  ret = 100000000;
  for (int i = 1; i <= m; i++) ret = min(ret, arr[i][s][t]);
  if (rest == 0) return ret;
  for (int i = 1; i <= n; i++) {
    if (i == s || i == t) continue;
    ret = min(ret, dis[s][i] + solve(i, t, rest - 1));
  }
  return ret;
}
int main() {
  int i, j, k;
  int u, r, v, a, d, p;
  sc(n, m, r);
  for (p = 1; p <= m; p++) {
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        sc(arr[p][i][j]);
      }
    }
    for (k = 1; k <= n; k++) {
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
          if (i == j) continue;
          arr[p][i][j] = min(arr[p][i][j], arr[p][i][k] + arr[p][k][j]);
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dis[i][j] = 100000000;
      for (k = 1; k <= m; k++) dis[i][j] = min(dis[i][j], arr[k][i][j]);
    }
  }
  memset(dp, -1, sizeof dp);
  int s, e;
  while (r--) {
    sc(s, e, k);
    k = min(n, k);
    printf("%d\n", solve(s, e, k));
  }
  return 0;
}
