#include <bits/stdc++.h>
using namespace std;
int n, m, r, in[100][100][100], dp[100][100][100];
void First_Warshal() {
  for (int c = 0; c < m; c++)
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          in[c][i][j] = min(in[c][i][j], in[c][i][k] + in[c][k][j]);
}
void Second_Warshal() {
  for (int c = 0; c < m; c++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) dp[0][i][j] = min(dp[0][i][j], in[c][i][j]);
  for (int c = 1; c < n - 1; c++)
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          dp[c][i][j] = min(dp[c][i][j], dp[c - 1][i][k] + dp[0][k][j]);
}
int main() {
  memset(dp, 1, sizeof dp);
  scanf("%d %d %d", &n, &m, &r);
  for (int c = 0; c < m; c++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) scanf("%d", &in[c][i][j]);
  First_Warshal();
  Second_Warshal();
  for (int i = 0; i < r; i++) {
    int st, en, k;
    scanf("%d %d %d", &st, &en, &k);
    st--, en--;
    k = min(k, n - 2);
    printf("%d\n", dp[k][st][en]);
  }
  return 0;
}
