#include <bits/stdc++.h>
using namespace std;
int dist[65][65], d[65][65], dp[65][65][65], n;
const int INF = 100000000;
int rec(int k, int s, int t) {
  if (s == t) return 0;
  if (k == 0) return INF;
  if (dp[k][s][t] != -1) return dp[k][s][t];
  int res = INF;
  for (int v = 0; v < (n); ++v) res = min(res, d[s][v] + rec(k - 1, v, t));
  return dp[k][s][t] = res;
}
int main(void) {
  int m, r;
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) d[i][j] = INF;
  }
  for (int l = 0; l < (m); ++l) {
    for (int i = 0; i < (n); ++i) {
      for (int j = 0; j < (n); ++j) scanf("%d", &dist[i][j]);
    }
    for (int k = 0; k < (n); ++k) {
      for (int i = 0; i < (n); ++i) {
        for (int j = 0; j < (n); ++j)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
    for (int i = 0; i < (n); ++i) {
      for (int j = 0; j < (n); ++j) d[i][j] = min(d[i][j], dist[i][j]);
    }
  }
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < (r); ++i) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    --s;
    --t;
    printf("%d\n", rec(min(k + 1, 63), s, t));
  }
  return 0;
}
