#include <bits/stdc++.h>
using namespace std;
int n, m, q, e[65][65][65], d[65][65][65];
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++)
      for (int k = (0); k <= (n); k++) d[i][j][k] = 1e9;
  for (int i = (1); i <= (m); i++) {
    for (int j = (1); j <= (n); j++)
      for (int k = (1); k <= (n); k++) scanf("%d", &e[i][j][k]);
    for (int w = (1); w <= (n); w++)
      for (int j = (1); j <= (n); j++)
        for (int k = (1); k <= (n); k++)
          e[i][j][k] = min(e[i][j][k], e[i][j][w] + e[i][w][k]);
    for (int j = (1); j <= (n); j++)
      for (int k = (1); k <= (n); k++) d[j][k][0] = min(d[j][k][0], e[i][j][k]);
  }
  for (int z = (1); z <= (n); z++)
    for (int k = (1); k <= (n); k++)
      for (int i = (1); i <= (n); i++)
        for (int j = (1); j <= (n); j++)
          d[i][j][z] = min(d[i][j][z], min(d[i][k][z - 1] + d[k][j][0],
                                           d[i][k][0] + d[k][j][z - 1]));
  while (q--) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    c = min(c, n);
    printf("%d\n", d[a][b][c]);
  }
  scanf("\n");
}
