#include <bits/stdc++.h>
using namespace std;
int g[65][65][65];
int f[65][65][65];
int main() {
  int n, m, r;
  scanf("%d%d%d", &n, &m, &r);
  memset(g, 0x7f, sizeof(g));
  memset(f, 0x7f, sizeof(f));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) scanf("%d", &g[i][j][k]);
  for (int id = 1; id <= m; id++)
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          g[id][i][j] = min(g[id][i][j], g[id][i][k] + g[id][k][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= m; k++) f[i][j][0] = min(f[i][j][0], g[k][i][j]);
  for (int kk = 1; kk <= n; kk++)
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          f[i][j][kk] = min(f[i][j][kk], f[i][k][kk - 1] + f[k][j][0]);
  while (r--) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    k = min(k, n);
    printf("%d\n", f[s][t][k]);
  }
  return 0;
}
