#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
int cmp(double x, double y = 0, double tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
int cities, cars, rounds;
const int MAXN = 62;
int speed[MAXN][MAXN][MAXN];
int single[MAXN][MAXN];
int ans[MAXN][MAXN][1005];
const int oo = 1 << 30;
int main() {
  scanf("%d %d %d", &cities, &cars, &rounds);
  for (int i = 0; i < cities; ++i) {
    for (int j = 0; j < cities; ++j) {
      single[i][j] = oo;
    }
  }
  for (int c = 0; c < cars; ++c) {
    for (int i = 0; i < cities; ++i) {
      for (int j = 0; j < cities; ++j) {
        scanf("%d", &speed[c][i][j]);
      }
    }
    for (int k = 0; k < cities; ++k) {
      for (int i = 0; i < cities; ++i) {
        for (int j = 0; j < cities; ++j) {
          if ((speed[c][i][k] + speed[c][k][j]) < (speed[c][i][j]))
            (speed[c][i][j]) = (speed[c][i][k] + speed[c][k][j]);
          if ((speed[c][i][j]) < (single[i][j]))
            (single[i][j]) = (speed[c][i][j]);
        }
      }
    }
  }
  memset(ans, -1, sizeof ans);
  while (rounds--) {
    int start, finish, changes;
    scanf("%d %d %d", &start, &finish, &changes);
    start--, finish--;
    if (ans[start][finish][changes] != -1) {
      printf("%d\n", ans[start][finish][changes]);
      continue;
    }
    for (int c = 0; c < cities; ++c) {
      ans[c][finish][0] = single[c][finish];
    }
    for (int k = 1; k <= 1000; ++k) {
      for (int c = 0; c < cities; ++c) {
        ans[c][finish][k] = oo;
        for (int v = 0; v < cities; ++v) {
          int option = single[c][v] + ans[v][finish][k - 1];
          if ((option) < (ans[c][finish][k])) (ans[c][finish][k]) = (option);
        }
      }
    }
    printf("%d\n", ans[start][finish][changes]);
  }
  return 0;
}
