#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793238462;
int n, m, r, w[70][70][70], d[70][70][2000], a, b, c;
const int inf = 2000000000;
void deb(int q) {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) printf("%d ", d[i][j][q]);
    printf("\n");
  }
  printf("\n");
}
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", &w[j][k][i]);
  for (int t = 1; t <= m; t++)
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          w[i][j][t] = min(w[i][j][t], w[i][k][t] + w[k][j][t]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      d[i][j][0] = inf;
      for (int t = 1; t <= m; t++) d[i][j][0] = min(d[i][j][0], w[i][j][t]);
    }
  for (int i = 1; i <= 1000; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) {
        d[j][k][i] = inf;
        for (int q = 1; q <= n; q++)
          d[j][k][i] = min(d[j][k][i], d[j][q][i - 1] + d[q][k][0]);
      }
  for (int i = 1; i <= r; i++) {
    scanf("%d%d%d", &a, &b, &c);
    printf("%d\n", d[a][b][c]);
  }
  return 0;
}
