#include <bits/stdc++.h>
using namespace std;
template <class T>
int popcount(T n);
template <>
int popcount(unsigned int n) {
  return n ? __builtin_popcount(n) : 0;
}
template <>
int popcount(int n) {
  return n ? __builtin_popcount(n) : 0;
}
template <>
int popcount(unsigned long long n) {
  return n ? __builtin_popcountll(n) : 0;
}
template <>
int popcount(long long n) {
  return n ? __builtin_popcountll(n) : 0;
}
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool valid_pos(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
template <class T>
void print(T a, int n, int br = 1, const string& deli = ", ") {
  cout << "{ ";
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if (i + 1 != n) cout << deli;
  }
  cout << " }";
  while (br--) cout << endl;
}
template <class T>
void print(const vector<T>& v, int br = 1, const string& deli = ", ") {
  print(v, v.size(), br, deli);
}
int main() {
  ios::sync_with_stdio(false);
  int n, m, r;
  cin >> n >> m >> r;
  const int INF = 1 << 29;
  int e[64][64];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) e[i][j] = INF;
  while (m--) {
    int c[64][64];
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) cin >> c[i][j];
    for (int k = 0; k < n; ++k)
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) min_swap(c[i][j], c[i][k] + c[k][j]);
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) min_swap(e[i][j], c[i][j]);
  }
  static int dp[64][64][64];
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < n; ++k) dp[i][j][k] = INF;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) dp[0][i][j] = e[i][j];
  for (int t = 0; t < n; ++t)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        for (int k = 0; k < n; ++k)
          min_swap(dp[t + 1][i][j], dp[t][i][k] + e[k][j]);
  while (r--) {
    int s, t, k;
    cin >> s >> t >> k;
    --s, --t;
    cout << dp[min(n, k)][s][t] << endl;
  }
}
