#include <bits/stdc++.h>
using namespace std;
array<array<int, 60>, 60> combine(array<array<int, 60>, 60> l,
                                  array<array<int, 60>, 60> r) {
  array<array<int, 60>, 60> ret;
  fill_n(&ret[0][0], 60 * 60, 1000000000);
  for (int k = 0; k < 60; k++)
    for (int i = 0; i < 60; i++)
      for (int j = 0; j < 60; j++)
        ret[i][j] = min(ret[i][j], l[i][k] + r[k][j]);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  vector<array<array<int, 60>, 60> > optimalTraversal(60);
  fill_n(&optimalTraversal[0][0][0], 60 * 60, 1000000000);
  for (int cind = 0; cind < m; cind++) {
    array<array<int, 60>, 60> dist;
    fill_n(&dist[0][0], 60 * 60, 1000000000);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) cin >> dist[i][j];
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        optimalTraversal[0][i][j] = min(optimalTraversal[0][i][j], dist[i][j]);
  }
  for (int i = 1; i < n; i++)
    optimalTraversal[i] = combine(optimalTraversal[i - 1], optimalTraversal[0]);
  for (int QUERY = 0; QUERY < r; QUERY++) {
    int s, t, k;
    cin >> s >> t >> k;
    k = min(k, n - 1);
    s--, t--;
    cout << optimalTraversal[k][s][t] << '\n';
  }
  return 0;
}
