#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6 * 10 + 5, MAXM = 10 * 10 * 10 + 10;
long long dis[MAXN][MAXN][MAXN], d[MAXM][MAXN][MAXN], mn[MAXM][MAXN][MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, r;
  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++) cin >> dis[i][j][k];
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        for (int l = 0; l < n; l++)
          dis[i][l][k] = min(dis[i][l][k], dis[i][l][j] + dis[i][j][k]);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < m; k++)
        if (k == 0 or dis[k][i][j] < d[0][i][j]) d[0][i][j] = dis[k][i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 1; k < MAXN; k++) d[k][i][j] = MAXM * MAXM * MAXM;
  for (int k = 1; k < MAXN; k++)
    for (int t = 0; t < n; t++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          d[k][i][j] = min(d[k][i][j], d[k - 1][i][t] + d[0][t][j]);
  int x, y, l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < MAXN; k++) {
        if (k == 0)
          mn[k][i][j] = d[k][i][j];
        else
          mn[k][i][j] = min(d[k][i][j], mn[k - 1][i][j]);
      }
  for (int i = 0; i < r; i++) {
    cin >> x >> y >> l;
    x--;
    y--;
    l = min(l, n - 1);
    cout << mn[l][x][y] << endl;
  }
  return 0;
}
