#include <bits/stdc++.h>
using namespace std;
int car[64][64][64];
int sp[64][64][64];
const int INF = 1e9;
void solve() {
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i < (int)(m); ++i) {
    for (int j = 0; j < (int)(n); ++j)
      for (int k = 0; k < (int)(n); ++k) cin >> car[i][j][k];
  }
  for (int c = 0; c < (int)(m); ++c) {
    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 (car[c][i][j] > car[c][i][k] + car[c][k][j])
            car[c][i][j] = car[c][i][k] + car[c][k][j];
  }
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(n); ++j) {
      sp[i][j][0] = INF;
      for (int k = 0; k < (int)(m); ++k)
        if (sp[i][j][0] > car[k][i][j]) sp[i][j][0] = car[k][i][j];
    }
  for (int k = (int)(1); k < (int)(n); ++k)
    for (int i = 0; i < (int)(n); ++i)
      for (int j = 0; j < (int)(n); ++j) {
        sp[i][j][k] = sp[i][j][k - 1];
        for (int q = 0; q < (int)(n); ++q) {
          sp[i][j][k] = min(sp[i][j][k], sp[i][q][k - 1] + sp[q][j][0]);
        }
      }
  for (int i = 0; i < (int)(r); ++i) {
    int s, e, mc;
    cin >> s >> e >> mc;
    s--, e--;
    mc = min(mc, n - 1);
    cout << sp[s][e][mc] << endl;
  }
}
int main() {
  solve();
  return 0;
}
