#include <bits/stdc++.h>
using namespace std;
const int maxn = 64;
int n, m, r, a[maxn][maxn], dis[maxn];
int dp[maxn][maxn][maxn];
set<pair<int, int> > s;
void dij(int v) {
  memset(dis, 127, sizeof dis);
  dis[v] = 0;
  s.insert(make_pair(dis[v], v));
  while (s.size()) {
    v = s.begin()->second;
    s.erase(s.begin());
    for (int u = 0; u < n; u++)
      if (dis[v] + a[v][u] < dis[u]) {
        s.erase(make_pair(dis[u], u));
        dis[u] = dis[v] + a[v][u];
        s.insert(make_pair(dis[u], u));
      }
  }
}
void set_distance() {
  memset(dis, 127, sizeof dis);
  for (int i = 0; i < n; i++) {
    dij(i);
    for (int j = 0; j < n; j++)
      if (dis[j] < dp[i][j][0]) dp[i][j][0] = dis[j];
  }
}
void update_dp() {
  for (int k = 1; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int l = 0; l < n; l++)
          dp[i][j][k] = min(dp[i][j][k], dp[i][l][k - 1] + dp[l][j][0]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> r;
  memset(dp, 31, sizeof dp);
  while (m--) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) cin >> a[i][j];
    set_distance();
  }
  update_dp();
  for (int S, T, k; r--;) {
    cin >> S >> T >> k;
    cout << dp[S - 1][T - 1][min(k, n - 2)] << endl;
  }
  return 0;
}
