#include <bits/stdc++.h>
using namespace std;
long long dp[61][61][61], d[61][61][61], m, n, r, s, l, ch;
long long solve(long long s, long long t, long long kleft) {
  if (kleft < 0) return 1e18;
  if (s == t) return 0;
  long long &ans = dp[s][t][kleft];
  if (ans != -1) return ans;
  ans = 1e18;
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++)
      ans = min(ans, d[s][i][j] + solve(i, t, kleft - 1));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> r;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k <= n; k++) dp[i][j][k] = 1e18;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) cin >> d[j][k][i];
  for (int l = 1; l <= m; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++)
          d[j][k][l] = min(d[j][k][l], d[j][i][l] + d[i][k][l]);
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) dp[j][k][0] = min(dp[j][k][0], d[j][k][i]);
  for (int k = 1; k <= n; k++)
    for (int s = 1; s <= n; s++)
      for (int t = 1; t <= n; t++)
        for (int j = 1; j <= n; j++)
          dp[s][t][k] = min(dp[s][t][k], dp[s][j][k - 1] + dp[j][t][0]);
  while (r--) {
    cin >> s >> l >> ch;
    ch = min(ch, n);
    cout << dp[s][l][ch] << "\n";
  }
  return 0;
}
