#include <bits/stdc++.h>
using namespace std;
const int NN = 77;
const int CHANGE = 1111;
const int INF = 1 << 29;
int n, m, r;
int G[NN][NN][NN];
int dp[NN][NN][NN];
int get_min[NN][NN];
int rec(int end, int pos, int k) {
  if (k == -1) return INF;
  if (pos == end) return 0;
  int &res = dp[end][pos][k];
  if (~res) return res;
  res = INF;
  for (int i = 0; i < n; i++) {
    res = min(res, rec(end, i, k - 1) + get_min[pos][i]);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  scanf("%d%d%d", &n, &m, &r);
  for (int car = 0; car < m; car++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) scanf("%d", &G[car][i][j]);
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          G[car][i][j] = min(G[car][i][j], G[car][i][k] + G[car][k][j]);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      get_min[i][j] = INF;
      for (int car = 0; car < m; car++) {
        get_min[i][j] = min(get_min[i][j], G[car][i][j]);
      }
    }
  memset(dp, -1, sizeof(dp));
  int src, sink, change;
  int res;
  while (r--) {
    scanf("%d%d%d", &src, &sink, &change);
    src--;
    sink--;
    change = min(61, change);
    res = rec(sink, src, change + 1);
    printf("%d\n", res);
  }
}
