#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 7e18;
const long double EPS = 1e-9;
const long double PI = 3.14159265358979310000;
const long long MD = 535355424;
const int T = 1e5 * 3;
const int N = 400101;
const int M = 61;
int n, m, r, a[M][M][M], d[M][M][M];
int main() {
  cin >> n >> m >> r;
  for (int u = 0; u < int(m); u++)
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(n); j++) scanf("%d", &a[u][i][j]);
  for (int u = 0; u < int(M); u++)
    for (int i = 0; i < int(M); i++)
      for (int j = 0; j < int(M); j++) d[u][i][j] = INF;
  for (int u = 0; u < int(m); u++)
    for (int k = 0; k < int(n); k++)
      for (int i = 0; i < int(n); i++)
        for (int j = 0; j < int(n); j++)
          a[u][i][j] = min(a[u][i][j], a[u][i][k] + a[u][k][j]);
  for (int u = 0; u < int(m); u++)
    for (int i = 0; i < int(n); i++)
      for (int j = 0; j < int(n); j++) d[0][i][j] = min(d[0][i][j], a[u][i][j]);
  for (int u = 0; u < int(n); u++)
    for (int k = 0; k < int(n); k++)
      for (int i = 0; i < int(n); i++)
        for (int j = 0; j < int(n); j++) {
          if (d[u + 1][i][j] >= d[u][i][k] + d[0][k][j])
            d[u + 1][i][j] = d[u][i][k] + d[0][k][j];
          if (d[u + 1][i][j] >= d[0][i][k] + d[u][k][j])
            d[u + 1][i][j] = d[0][i][k] + d[u][k][j];
        }
  for (int i = 0; i < int(r); i++) {
    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);
    a--;
    b--;
    k = min(k, n - 1);
    printf("%d\n", d[k][a][b]);
  }
  return 0;
}
