#include <bits/stdc++.h>
using namespace std;
int g[70][70][70] = {0};
int dp[70][70][70] = {0};
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i < (70 - 1 + 1); ++i)
    for (int j = 0; j < (70 - 1 + 1); ++j)
      for (int k = 0; k < (70 - 1 + 1); ++k) g[i][j][k] = dp[i][j][k] = 9999999;
  for (int i = 1; i < (m + 1); ++i)
    for (int j = 1; j < (n + 1); ++j)
      for (int k = 1; k < (n + 1); ++k) cin >> g[i][j][k];
  for (int car = 1; car < (m + 1); ++car)
    for (int k = 1; k < (n + 1); ++k)
      for (int i = 1; i < (n + 1); ++i)
        for (int j = 1; j < (n + 1); ++j)
          g[car][i][j] = min(g[car][i][j], g[car][i][k] + g[car][k][j]);
  for (int i = 1; i < (n + 1); ++i)
    for (int j = 1; j < (n + 1); ++j)
      for (int car = 1; car < (m + 1); ++car)
        dp[i][j][0] = min(dp[i][j][0], g[car][i][j]);
  for (int vary = 1; vary < (n + 1); ++vary)
    for (int k = 1; k < (n + 1); ++k)
      for (int i = 1; i < (n + 1); ++i)
        for (int j = 1; j < (n + 1); ++j)
          dp[i][j][vary] =
              min(dp[i][j][vary], dp[i][k][vary - 1] + dp[k][j][0]);
  while (r--) {
    int s, t, k;
    cin >> s >> t >> k;
    k = min(n, k);
    cout << dp[s][t][k] << endl;
  }
  return 0;
}
