#include <bits/stdc++.h>
using namespace std;
const int N = 62;
const double eps = 1e-9;
const int oo = 1000000000;
int n, c, r;
int road[N][N][N], dm[N][N], f[N][N][1100];
void init() {
  scanf("%d%d%d", &n, &c, &r);
  memset(dm, 127, sizeof(dm));
  for (int cc = 0; cc < c; ++cc) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= n; ++k) {
        scanf("%d", &road[cc][j][k]);
      }
    }
    for (int k = 1; k <= n; ++k) {
      for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
          road[cc][i][j] = min(road[cc][i][j], road[cc][i][k] + road[cc][k][j]);
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        dm[i][j] = min(dm[i][j], road[cc][i][j]);
      }
    }
  }
}
void solve() {
  memset(f, 127, sizeof(f));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      f[i][j][0] = dm[i][j];
    }
  }
  for (int s = 1; s <= 1000; ++s) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        for (int l = 1; l <= n; ++l) {
          f[i][j][s] = min(f[i][l][s - 1] + dm[l][j], f[i][j][s]);
        }
      }
    }
  }
}
void query() {
  while (r--) {
    int s, t, k;
    scanf("%d%d%d", &s, &t, &k);
    printf("%d\n", f[s][t][k]);
  }
}
int main() {
  init();
  solve();
  query();
  return 0;
}
