#include <bits/stdc++.h>
using namespace std;
int T, M, R;
int tm[62][62];
int race[62][62][62];
int main() {
  scanf("%d%d%d", &T, &M, &R);
  for (int a = 0; a < T; a++)
    for (int b = 0; b < T; b++) race[0][a][b] = 1999222;
  for (int m = 0; m < M; m++) {
    for (int a = 0; a < T; a++)
      for (int b = 0; b < T; b++) scanf("%d", &tm[a][b]);
    for (int k = 0; k < T; k++)
      for (int a = 0; a < T; a++)
        for (int b = 0; b < T; b++) {
          tm[a][b] = min(tm[a][b], tm[a][k] + tm[k][b]);
        }
    for (int a = 0; a < T; a++)
      for (int b = 0; b < T; b++) race[0][a][b] = min(race[0][a][b], tm[a][b]);
  }
  for (int j = 1; j < T; j++) {
    for (int a = 0; a < T; a++)
      for (int b = 0; b < T; b++) {
        race[j][a][b] = race[j - 1][a][b];
      }
    for (int k = 0; k < T; k++)
      for (int a = 0; a < T; a++)
        for (int b = 0; b < T; b++) {
          race[j][a][b] = min(race[j][a][b], race[0][a][k] + race[j - 1][k][b]);
        }
  }
  for (int r = 0; r < R; r++) {
    int a, b, s;
    scanf("%d%d%d", &a, &b, &s);
    s = min(T - 1, s);
    printf("%d\n", race[s][--a][--b]);
  }
}
