#include <bits/stdc++.h>
using namespace std;
const int N = 65;
pair<int, unsigned long long> mt[2 * N][N][N];
pair<int, unsigned long long> base[N][N];
int cur[N][N];
int n, m, q;
void upd(pair<int, unsigned long long> &wh, int dist, unsigned long long mask) {
  if (wh.first == dist)
    wh.second |= mask;
  else if (wh.first > dist) {
    wh.first = dist;
    wh.second = mask;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int t = 0; t < m; t++) {
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) cin >> cur[j][k];
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          cur[i][j] = min(cur[i][j], cur[i][k] + cur[k][j]);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (t == 0)
          mt[0][i][j] = make_pair(cur[i][j], 1ll << t);
        else
          upd(mt[0][i][j], cur[i][j], 1ll << t);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) base[i][j] = mt[0][i][j];
  for (int t = 0; t < 2 * N - 1; t++) {
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
          unsigned long long m1 = mt[t][i][k].second, m2 = base[k][j].second;
          if (m1 & m2) {
            upd(mt[t][i][j], mt[t][i][k].first + base[k][j].first, m1 & m2);
          }
        }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        mt[t + 1][i][j] = mt[t][i][j];
        for (int k = 0; k < n; k++) {
          upd(mt[t + 1][i][j], mt[t][i][k].first + base[k][j].first,
              base[k][j].second);
        }
      }
  }
  for (int i = 0; i < q; i++) {
    int st, fi, ki;
    cin >> st >> fi >> ki;
    ki = min(ki, 2 * N - 1);
    st--;
    fi--;
    cout << mt[ki][st][fi].first << "\n";
  }
  return 0;
}
