#include <bits/stdc++.h>
using namespace std;
const int oo = 1e8;
int N, M, R, V;
int a[70][70][70], save[11][11][101][11], D[70][70][70], memo[70][70][70];
int S[200000], T[200000], K[200000];
int POW(int a, int n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  if (n % 2 == 0)
    return POW(a, n / 2) * POW(a, n / 2);
  else
    return POW(a, n / 2) * POW(a, n / 2) * a;
}
int solve(int tp, int xe, int k, int mask) {
  if (k > K[V]) return oo;
  if (tp == T[V]) return 0;
  if (save[tp][xe][k][mask] != -1) return save[tp][xe][k][mask];
  int cur = oo;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      if ((mask & (1 << (i - 1))) == 0) {
        if (xe != j) {
          cur =
              min(cur, solve(i, j, k + 1, mask | (1 << (i - 1))) + a[j][tp][i]);
        } else {
          cur = min(cur, solve(i, j, k, mask | (1 << (i - 1))) + a[j][tp][i]);
        }
      }
    }
  }
  return save[tp][xe][k][mask] = cur;
}
void slow() {
  for (V = 1; V <= R; ++V) {
    int res = oo;
    for (int i = 1; i <= M; ++i) {
      for (int s1 = 1; s1 <= N; ++s1) {
        for (int s2 = 1; s2 <= M; ++s2) {
          for (int s3 = 0; s3 <= K[V]; ++s3) {
            for (int s4 = 0; s4 <= POW(2, N); ++s4) {
              save[s1][s2][s3][s4] = -1;
            }
          }
        }
      }
      res = min(res, solve(S[V], i, 0, 0));
    }
    cout << res << '\n';
  }
  exit(0);
}
void floyd() {
  for (int xe = 1; xe <= M; ++xe) {
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= N; ++j) {
        D[xe][i][j] = oo;
      }
    }
  }
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= N; ++j) {
      D[i][j][j] = 0;
      for (int k = 1; k <= N; ++k) {
        D[i][j][k] = a[i][j][k];
      }
    }
  }
  for (int xe = 1; xe <= M; ++xe) {
    for (int k = 1; k <= N; ++k) {
      for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
          D[xe][i][j] = min(D[xe][i][j], D[xe][i][k] + D[xe][k][j]);
        }
      }
    }
  }
}
int solve(int u, int v, int k) {
  if (memo[u][v][k] != -1) return memo[u][v][k];
  if (k == 0) {
    int cur = oo;
    for (int i = 1; i <= M; ++i) {
      cur = min(cur, D[i][u][v]);
    }
    return memo[u][v][k] = cur;
  }
  int cur = oo;
  for (int i = 1; i <= N; ++i) {
    cur = min(cur, solve(u, i, k - 1) + solve(i, v, 0));
  }
  return memo[u][v][k] = cur;
}
void fast() {
  floyd();
  memset(memo, -1, sizeof(memo));
  for (int i = 1; i <= R; ++i) {
    cout << solve(S[i], T[i], K[i]) << "\n";
  }
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M >> R;
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= N; ++k) {
        cin >> a[i][j][k];
      }
    }
  }
  for (int i = 1; i <= R; ++i) {
    cin >> S[i] >> T[i] >> K[i];
    K[i] = min(N, K[i]);
  }
  fast();
}
