#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000;
int n, m, r;
int s, t, k;
int fw[61][61][61];
int ret[61][61][61];
int main() {
  cin >> n >> m >> r;
  for (int h = 1; h <= m; ++h)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) cin >> fw[h][i][j];
  for (int h = 1; h <= m; ++h)
    for (int k = 1; k <= n; ++k)
      for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
          fw[h][i][j] = min(fw[h][i][j], fw[h][i][k] + fw[h][k][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      ret[0][i][j] = MAX;
      for (int h = 1; h <= m; ++h)
        ret[0][i][j] = min(ret[0][i][j], fw[h][i][j]);
    }
  for (int c = 1; c <= n; ++c)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) {
        ret[c][i][j] = MAX;
        for (int k = 1; k <= n; ++k)
          ret[c][i][j] = min(ret[c][i][j], ret[c - 1][i][k] + ret[0][k][j]);
      }
  for (int i = 0; i < r; ++i) {
    cin >> s >> t >> k;
    cout << ret[min(n, k)][s][t] << endl;
  }
  return 0;
}
