#include <bits/stdc++.h>
using namespace ::std;
const long double PI = acos(-1);
const long long MOD = 1000000000 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long add(long long a, long long b, long long m = MOD) {
  return (a % m + b % m + 2 * m) % m;
}
long long mul(long long a, long long b, long long m = MOD) {
  return ((a % m + m) * (b % m + m)) % m;
}
long long pow_mod(long long a, long long b, long long m = MOD) {
  long long res = 1LL;
  a = a % m;
  while (b) {
    if (b & 1) res = mul(res, a, m);
    b >>= 1;
    a = mul(a, a, m);
  }
  return res;
}
long long fastexp(long long a, long long b) {
  long long res = 1LL;
  while (b) {
    if (b & 1) res = res * a;
    b >>= 1;
    a *= a;
  }
  return res;
}
int gcdExtendido(int a, int b, int *x, int *y) {
  if (a == 0) {
    *x = 0;
    *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtendido(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
int modInverso(int a, int m) {
  int x, y;
  int g = gcdExtendido(a, m, &x, &y);
  if (g != 1)
    return -1;
  else
    return (x % m + m) % m;
}
const int N = 60 + 5;
const int K = 1000 + 5;
int n, m, r;
long long d[N][N][N];
long long ans[N][N][N];
long long t[N][N][N][N];
void floydWarshall(int id) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[id][i][j] > d[id][i][k] + d[id][k][j]) {
          d[id][i][j] = d[id][i][k] + d[id][k][j];
        }
      }
    }
  }
}
void solve() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      ans[0][i][j] = -1LL;
      for (int c = 0; c < m; c++) {
        if (ans[0][i][j] > d[c][i][j] or ans[0][i][j] == -1LL) {
          ans[0][i][j] = d[c][i][j];
        }
      }
    }
  }
  for (int ch = 1; ch < n; ch++) {
    for (int u = 0; u < n; u++) {
      for (int v = 0; v < n; v++) {
        if (u == v) continue;
        ans[ch][u][v] = -1LL;
      }
    }
    for (int l = 0; l < n; l++) {
      for (int u = 0; u < n; u++) {
        for (int v = 0; v < n; v++) {
          if (ans[ch][u][v] > ans[ch - 1][u][l] + ans[0][l][v] or
              ans[ch][u][v] == -1) {
            ans[ch][u][v] = ans[ch - 1][u][l] + ans[0][l][v];
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &(n), &(m), &(r));
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        scanf("%lld", &(d[k][i][j]));
      }
    }
  }
  for (int i = 0; i < m; i++) {
    floydWarshall(i);
  }
  solve();
  int u, v, k;
  while (r--) {
    scanf("%d %d %d", &(u), &(v), &(k));
    u--;
    v--;
    if (k >= n) {
      printf("%lld\n", ans[n - 1][u][v]);
    } else {
      printf("%lld\n", ans[k][u][v]);
    }
  }
  return 0;
}
