#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u >> 1;
int ans[65][65][1005];
struct Car {
  int tim[65][65];
} c[65];
int min(int a, int b) { return a < b ? a : b; }
void Floyed(Car &a, int n) {
  int i, j, k;
  for (k = 1; k <= n; k++)
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++)
        a.tim[i][j] = min(a.tim[i][j], a.tim[i][k] + a.tim[k][j]);
  return;
}
int main() {
  int n, m, r, i, j, k, l, S, T, K;
  cin >> n >> m >> r;
  for (k = 1; k <= m; k++) {
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) cin >> c[k].tim[i][j];
    Floyed(c[k], n);
  }
  for (i = 0; i < 65; i++)
    for (j = 0; j < 65; j++)
      for (k = 0; k < 1005; k++) ans[i][j][k] = inf;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      for (k = 1; k <= m; k++) ans[i][j][0] = min(ans[i][j][0], c[k].tim[i][j]);
  for (l = 1; l < 1005; l++)
    for (k = 1; k <= n; k++)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
          ans[i][j][l] = min(ans[i][j][l], ans[i][k][l - 1] + ans[k][j][0]);
  while (r--) cin >> S >> T >> K, cout << ans[S][T][K] << endl;
  return 0;
}
