#include <bits/stdc++.h>
using namespace std;
int val[64][64][64];
int w[64][64];
int c[64][64];
int n, m, r;
bool vis[64];
void floyd(int u) {
  int i, j, k;
  for (k = 1; k <= n; k++)
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++)
        if (w[i][j] > w[i][k] + w[k][j]) w[i][j] = w[i][k] + w[k][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (val[i][j][0] > w[i][j]) val[i][j][0] = w[i][j];
}
void solve() {
  int i, j, k, l;
  for (k = 1; k <= n - 2; k++)
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) {
        val[i][j][k] = val[i][j][k - 1];
        for (l = 1; l <= n; l++) {
          if (val[i][j][k] > val[i][l][k - 1] + val[l][j][0]) {
            val[i][j][k] = val[i][l][k - 1] + val[l][j][0];
          }
        }
      }
}
int main() {
  int i, j, k;
  int u, v, rr, mn;
  scanf("%d%d%d", &n, &m, &r);
  for (i = 0; i < 64; i++)
    for (j = 0; j < 64; j++)
      for (k = 0; k < 64; k++) val[i][j][k] = (int)1e9;
  for (i = 0; i < m; i++) {
    for (j = 1; j <= n; j++)
      for (k = 1; k <= n; k++) scanf("%d", w[j] + k);
    floyd(i);
  }
  solve();
  mn = (int)1e9;
  for (i = 0; i < r; i++) {
    scanf("%d%d%d", &u, &v, &rr);
    rr = min(n - 2, rr);
    printf("%d\n", val[u][v][rr]);
  }
  return 0;
}
