#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long mx = 1e5 + 5;
long long a[65][65][65], ans[65][65][65];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, r;
  cin >> n >> m >> r;
  for (long long i = 0; i < 65; i++)
    for (long long j = 0; j < 65; j++)
      for (long long k = 0; k < 65; k++) ans[i][j][k] = 1e18;
  for (long long i = 0; i < m; i++)
    for (long long j = 0; j < n; j++)
      for (long long k = 0; k < n; k++) cin >> a[j][k][i];
  for (long long i = 0; i < m; i++)
    for (long long j = 0; j < n; j++)
      for (long long k = 0; k < n; k++)
        for (long long l = 0; l < n; l++)
          a[k][l][i] = min(a[k][l][i], a[k][j][i] + a[j][l][i]);
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++)
      for (long long k = 0; k < m; k++)
        ans[i][j][0] = min(ans[i][j][0], a[i][j][k]);
  for (long long k = 1; k < 65; k++) {
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < n; j++)
        for (long long l = 0; l < n; l++)
          ans[i][j][k] = min(ans[i][j][k], ans[i][l][k - 1] + ans[l][j][0]);
  }
  while (r--) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (c >= 65) c = 64;
    cout << ans[a - 1][b - 1][c] << "\n";
  }
  return 0;
}
