#include <bits/stdc++.h>
using namespace std;
const int MAXN = 70;
set<pair<int, int> > s;
int dp[MAXN][MAXN][MAXN], dis[MAXN], a[MAXN][MAXN];
int n, m, r;
void dij() {
  while (!s.empty()) {
    pair<int, int> p = *(s.begin());
    s.erase(s.begin());
    int v = p.second, d = p.first;
    for (int i = 1; i <= n; i++) {
      if (dis[i] > d + a[v][i]) {
        s.erase(make_pair(dis[i], i));
        dis[i] = d + a[v][i];
        s.insert(make_pair(d + a[v][i], i));
      }
    }
  }
}
void disup() {
  for (int i = 1; i <= n; i++) {
    memset(dis, 127, sizeof dis);
    s.insert(make_pair(0, i));
    dij();
    for (int j = 1; j <= n; j++) dp[0][i][j] = min(dp[0][i][j], dis[j]);
  }
}
void finish_dp() {
  for (int l = 1; l <= n; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++)
          dp[l][i][j] = min(dp[l][i][j], dp[l - 1][i][k] + dp[0][k][j]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> r;
  memset(dp, 127, sizeof dp);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) cin >> a[j][k];
    disup();
  }
  finish_dp();
  for (int i = 1; i <= r; i++) {
    int v, u, k;
    cin >> v >> u >> k;
    k = min(k, n);
    cout << dp[k][v][u] << endl;
  }
  return 0;
}
