#include <bits/stdc++.h>
using namespace std;
long long c[70][70][70], d[70][70], ans[70][70][70];
int main() {
  long long n, m, r;
  cin >> n >> m >> r;
  for (long long car = 0; car < m; car++)
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < n; j++) cin >> c[car][i][j];
  for (long long car = 0; car < m; car++)
    for (long long k = 0; k < n; k++)
      for (long long i = 0; i < n; i++)
        for (long long j = 0; j < n; j++)
          c[car][i][j] = min(c[car][i][j], c[car][i][k] + c[car][k][j]);
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) d[i][j] = c[0][i][j];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++)
      for (long long k = 0; k < m; k++) d[i][j] = min(d[i][j], c[k][i][j]);
  for (long long t = 0; t < n + 1; t++)
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < n; j++) ans[t][i][j] = d[i][j];
  for (long long t = 0; t < n; t++)
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < n; j++)
        for (long long k = 0; k < n; k++)
          ans[t + 1][i][j] = min(ans[t + 1][i][j], ans[t][i][k] + d[k][j]);
  for (long long i = 0; i < r; i++) {
    long long s, t, k;
    cin >> s >> t >> k;
    s--;
    t--;
    cout << ans[min(k, n)][s][t] << endl;
  }
  return 0;
}
