#include <bits/stdc++.h>
using namespace std;
inline int ra() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int f[65][65][65], g[65][65][65];
int main() {
  int n = ra(), m = ra(), r = ra();
  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++) g[i][j][k] = ra();
  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 e = 1; e <= n; e++)
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          f[i][j][e] = min(f[i][j][e], f[i][k][e - 1] + f[k][j][0]);
  for (int i = 1; i <= r; i++) {
    int s = ra(), t = ra(), k = ra();
    k = min(k, n);
    printf("%d\n", f[s][t][k]);
  }
  return 0;
}
