#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const long long inf = (long long)1e17;
const int MAX_N = 200 * 1000 + 1000;
int n, m, r;
long long arr[66][66][66];
long long best[66][66];
long long dp[66][66][66];
bool visit[66][66][66];
void floyd() {
  for (int car = 0; car < m; car++) {
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          arr[car][i][j] = min(arr[car][i][j], arr[car][i][k] + arr[car][k][j]);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      best[i][j] = inf;
      for (int car = 0; car < m; car++) {
        best[i][j] = min(best[i][j], arr[car][i][j]);
      }
    }
  }
}
long long rec(int i, int j, int k) {
  if (i == j) return 0;
  if (k == 0) return inf;
  if (visit[i][j][k]) return dp[i][j][k];
  visit[i][j][k] = 1;
  long long &ref = dp[i][j][k];
  ref = inf;
  for (int h = 0; h < n; h++) {
    if (h == i) continue;
    ref = min(ref, best[i][h] + rec(h, j, k - 1));
  }
  return ref;
}
int main() {
  cin >> n >> m >> r;
  for (int rep = 0; rep < m; rep++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) cin >> arr[rep][i][j];
  floyd();
  for (int rep = 0; rep < r; rep++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    cout << rec(x, y, min(z + 1, 63)) << endl;
  }
  return 0;
}
