#include <bits/stdc++.h>
using namespace std;
template <class T>
T By(T x, T y, T P) {
  T F1 = 0;
  while (y) {
    if (y & 1) {
      F1 += x;
      if (F1 < 0 || F1 >= P) F1 -= P;
    }
    x <<= 1;
    if (x < 0 || x >= P) x -= P;
    y >>= 1;
  }
  return F1;
}
template <class T>
T Mul(T x, T y, T P) {
  T F1 = 1;
  x %= P;
  while (y) {
    if (y & 1) {
      F1 = By(F1, x, P);
    }
    x = By(x, x, P);
    y >>= 1;
  }
  return F1;
}
template <class T>
T Gcd(T x, T y) {
  if (y == 0) return x;
  T z;
  while (z = x % y) {
    x = y, y = z;
  }
  return y;
}
struct EDGE {
  int T;
  EDGE *Nxt;
};
template <class T>
void UpdataMin(T &x, T y) {
  if (y < x) {
    x = y;
  }
}
template <class T>
void UpdataMax(T &x, T y) {
  if (x < y) {
    x = y;
  }
}
int Dp[61][61][61];
int Map[61][61][61];
int NM[61][61];
int N, M, R, I, J, K;
int main() {
  memset(Dp, 63, sizeof(Dp));
  memset(NM, 63, sizeof(NM));
  scanf("%d%d%d", &N, &M, &R);
  for (int i = 0; i < (M); ++i) {
    for (int j = 1; j <= (N); ++j)
      for (int k = 1; k <= (N); ++k) scanf("%d", &Map[i][j][k]);
    for (int l = 1; l <= (N); ++l)
      for (int j = 1; j <= (N); ++j)
        for (int k = 1; k <= (N); ++k)
          if (Map[i][j][l] + Map[i][l][k] < Map[i][j][k])
            Map[i][j][k] = Map[i][j][l] + Map[i][l][k];
    for (int j = 1; j <= (N); ++j)
      for (int k = 1; k <= (N); ++k) UpdataMin(NM[j][k], Map[i][j][k]);
  }
  for (int i = 1; i <= (N); ++i)
    for (int j = 1; j <= (N); ++j) Dp[0][i][j] = NM[i][j];
  for (int i = 1; i <= (60); ++i)
    for (int j = 1; j <= (N); ++j)
      for (int k = 1; k <= (N); ++k)
        for (int l = 1; l <= (N); ++l)
          UpdataMin(Dp[i][j][l], Dp[i - 1][j][k] + NM[k][l]);
  while (R--) {
    scanf("%d%d%d", &I, &J, &K);
    if (K > 60) K = 60;
    printf("%d\n", Dp[K][I][J]);
  }
  scanf("%d", &N);
  return 0;
}
