#include <bits/stdc++.h>
const int oo = 66000000;
using namespace std;
int si, ti, ki, n, m, r, car[66][66], COST[66][66], f[66][66][66];
void Floyd() {
  for (long k = long(1); k <= long(n); k++)
    for (long i = long(1); i <= long(n); i++)
      for (long j = long(1); j <= long(n); j++)
        car[i][j] = min(car[i][j], car[i][k] + car[k][j]);
}
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (long t = long(1); t <= long(m); t++) {
    for (long i = long(1); i <= long(n); i++)
      for (long j = long(1); j <= long(n); j++) scanf("%d", &car[i][j]);
    Floyd();
    for (long i = long(1); i <= long(n); i++)
      for (long j = long(1); j <= long(n); j++)
        if (t == 1 || COST[i][j] > car[i][j]) COST[i][j] = car[i][j];
  }
  for (long i = long(1); i <= long(n); i++)
    for (long j = long(1); j <= long(n); j++)
      for (long t = long(0); t <= long(n); t++) f[i][j][t] = oo;
  for (long i = long(1); i <= long(n); i++)
    for (long j = long(1); j <= long(n); j++) f[i][j][0] = COST[i][j];
  for (long t = long(1); t <= long(n); t++)
    for (long i = long(1); i <= long(n); i++)
      for (long j = long(1); j <= long(n); j++)
        for (long k = long(1); k <= long(n); k++)
          f[i][j][t] = min(f[i][j][t], f[i][k][t - 1] + COST[k][j]);
  for (long i = long(1); i <= long(r); i++) {
    scanf("%d%d%d", &si, &ti, &ki);
    printf("%d\n", f[si][ti][min(n, ki)]);
  }
  return 0;
}
