#include <bits/stdc++.h>
using namespace std;
const int maxN = 60 + 10;
const long long INF = 100000 * 10000LL * 1000000;
int n, m, r;
long long dist[maxN][maxN], dp[maxN][maxN][maxN], d[maxN][maxN];
void floyed() {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
int main() {
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) scanf("%d", &dist[i][j]);
  }
  floyed();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) d[i][j] = dist[i][j];
  }
  for (int cars = 2; cars <= m; cars++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) scanf("%d", &dist[i][j]);
    }
    floyed();
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], dist[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) dp[i][j][0] = d[i][j];
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        long long minn = INF;
        for (int x = 1; x <= n; x++) {
          minn = min(dp[i][x][k - 1] + d[x][j], minn);
        }
        dp[i][j][k] = minn;
      }
    }
  }
  for (int i = 1; i <= r; i++) {
    int st, en, k;
    scanf("%d %d %d", &st, &en, &k);
    if (k > n)
      cout << dp[st][en][n] << endl;
    else
      cout << dp[st][en][k] << endl;
  }
  return 0;
}
