#include <bits/stdc++.h>
using namespace std;
int d[65][65][65], c[65][65][1005];
int main() {
  int n, m, r;
  cin >> 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", &d[j][k][i]);
      }
    }
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int t = 1; t <= n; t++) {
          d[k][t][i] = min(d[k][t][i], d[k][j][i] + d[j][t][i]);
        }
      }
    }
  }
  memset(c, 0x3f, sizeof(c));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= m; k++) {
        c[i][j][1] = min(d[i][j][k], c[i][j][1]);
      }
    }
  }
  for (int i = 2; i <= 201; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int t = 1; t <= n; t++) {
          c[k][t][i] = min(c[k][t][i], c[k][j][i - 1] + c[j][t][1]);
        }
      }
    }
  }
  while (r--) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    v = min(v, 200);
    printf("%d\n", c[x][y][v + 1]);
  }
}
