#include <bits/stdc++.h>
using namespace std;
long ans[200][70][70], d[200][70][70], dd[70][70], n, m, r, a, b, c;
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &r);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int q = 0; q < n; q++) scanf("%d", &d[i][j][q]);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int q = 0; q < n; q++)
        for (int w = 0; w < n; w++)
          d[i][q][w] = min(d[i][q][w], d[i][q][j] + d[i][j][w]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dd[i][j] = d[0][i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int q = 0; q < m; q++) dd[i][j] = min(dd[i][j], d[q][i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int q = 0; q <= n; q++) ans[q][i][j] = dd[i][j];
  for (int e = 0; e < n; e++)
    for (int j = 0; j < n; j++)
      for (int q = 0; q < n; q++)
        for (int p = 0; p < n; p++)
          ans[e + 1][j][q] = min(ans[e][j][p] + dd[p][q], ans[e + 1][j][q]);
  for (int i = 0; i < r; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    --a;
    --b;
    if (c > n) c = n;
    printf("%d\n", ans[c][a][b]);
  }
  cin.get();
  cin.get();
  return 0;
}
