#include <bits/stdc++.h>
using namespace std;
int n, m, r, A[63][63][63], sp[63][63][63], f[63][63][63];
int main() {
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        scanf("%d", &A[i][j][k]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int h = 1; h <= n; h++) {
          A[i][k][h] = min(A[i][k][h], A[i][k][j] + A[i][j][h]);
        }
      }
    }
  }
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= m; k++) f[0][i][j] = min(f[0][i][j], A[k][i][j]);
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int t = 1; t <= n; t++) {
          f[i][k][t] = min(f[i][k][t], f[i - 1][k][j] + f[0][j][t]);
        }
      }
    }
  }
  for (int i = 1; i <= r; i++) {
    int x, y, hak;
    scanf("%d %d %d", &x, &y, &hak);
    hak = min(hak, n - 1);
    printf("%d\n", f[hak][x][y]);
  }
  return 0;
}
