#include <bits/stdc++.h>
using namespace std;
int n, m, r, cast[65][65][65], ans[65][65][65];
int const inf = 999999;
int main() {
  memset(ans, 60, sizeof(ans));
  cin >> n >> m >> r;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) {
        int x;
        scanf("%d", &x);
        cast[i][j][k] = x;
      }
    for (int w = 0; w < n; w++)
      for (int u = 0; u < n; u++)
        for (int v = 0; v < n; v++)
          cast[i][u][v] = min(cast[i][u][v], cast[i][u][w] + cast[i][w][v]);
    for (int l = 0; l < n; l++)
      for (int a = 0; a < n; a++)
        ans[0][l][a] = min(ans[0][l][a], cast[i][l][a]);
  }
  for (int k = 1; k < 60; k++)
    for (int l = 0; l < n; l++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          ans[k][i][j] =
              min(ans[k][i][j], ans[k / 2][i][l] + ans[(k - 1) / 2][l][j]);
  for (int i = 0; i < r; i++) {
    int s, t, k;
    scanf("%d", &s);
    scanf("%d", &t);
    scanf("%d", &k);
    s--;
    t--;
    k = min(59, k);
    cout << ans[k][s][t] << endl;
  }
  return 0;
}
