#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ans = 0;
long long d[100][100][1001];
long long a[100][100][100];
long long b[100][100];
int main() {
  cin.tie();
  cout.tie();
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int l = 0; l < m; l++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) cin >> a[i][j][l];
  for (int l = 0; l < 1001; l++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) d[i][j][l] = (10e17 + 9);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) b[i][j] = (10e17 + 9);
  for (int s = 0; s < m; s++)
    for (int f = 0; f < n; f++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          a[i][j][s] = min(a[i][j][s], a[i][f][s] + a[f][j][s]);
  for (int s = 0; s < m; s++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) b[i][j] = min(b[i][j], a[i][j][s]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) d[i][j][0] = min(d[i][j][0], b[i][j]);
  for (int s = 1; s < 80; s++)
    for (int f = 0; f < n; f++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          d[i][j][s] = min(d[i][j][s], d[i][f][s - 1] + b[f][j]);
  for (int i = 0; i < k; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    if (z >= 80) z = 80 - 1;
    cout << d[x - 1][y - 1][z] << '\n';
  }
}
