#include <bits/stdc++.h>
using namespace std;
int n, m, q, s, t, dis[65][65][65], f[65][65][1005];
inline int read() {
  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 << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  m = read();
  q = read();
  int i, j, k, l, r;
  for (i = 0; i <= 1000; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) f[j][k][i] = 1e9;
    }
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) dis[i][j][k] = read();
    }
  }
  for (i = 1; i <= m; i++) {
    for (k = 1; k <= n; k++) {
      for (l = 1; l <= n; l++) {
        for (r = 1; r <= n; r++) {
          if (dis[i][l][r] > dis[i][l][k] + dis[i][k][r])
            dis[i][l][r] = dis[i][l][k] + dis[i][k][r];
        }
      }
    }
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++)
      for (k = 1; k <= n; k++) f[j][k][0] = min(f[j][k][0], dis[i][j][k]);
  }
  for (i = 1; i <= n; i++) {
    for (k = 1; k <= n; k++) {
      for (l = 1; l <= n; l++) {
        for (r = 1; r <= n; r++) {
          f[l][r][i] = min(f[l][r][i], f[l][k][i - 1] + f[k][r][0]);
        }
      }
    }
  }
  for (i = 1; i <= q; i++) {
    s = read();
    t = read();
    k = read();
    k = min(k, n);
    printf("%d\n", f[s][t][k]);
  }
  return 0;
}
