#include <bits/stdc++.h>
using namespace std;
int rec[61][61][61];
int n, m, r;
int minDist[61][61][62];
int d[60][60][60];
int INF = 999999999;
int solve(int now, int target, int remain) {
  if (now == target) return 0;
  if (remain == 0 && now == target) return 0;
  if (remain == 0) return INF;
  int &ret = minDist[now][target][remain];
  if (ret == -1) {
    ret = INF;
    for (int i = 1; i < 64; i <<= 1) {
      if (i > remain) break;
      for (int j = 0; j < (int)n; j++) {
        ret = min(ret, solve(j, target, remain - i) + rec[i][now][j]);
      }
    }
  }
  return ret;
}
int main() {
  memset(minDist, -1, sizeof(minDist));
  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 >> d[i][j][k];
      }
    }
  }
  for (int q = 0; q < m; q++) {
    for (int k = 0; k < (int)n; k++) {
      for (int i = 0; i < (int)n; i++) {
        for (int j = 0; j < (int)n; j++) {
          d[q][i][j] = min(d[q][i][j], d[q][i][k] + d[q][k][j]);
        }
      }
    }
  }
  int md = INF;
  for (int j = 0; j < (int)n; j++) {
    for (int k = 0; k < (int)n; k++) {
      md = INF;
      for (int s = 0; s < (int)m; s++) {
        md = min(d[s][j][k], md);
      }
      rec[1][j][k] = md;
    }
  }
  for (int q = 2; q < 64; q += q) {
    for (int i = 0; i < (int)n; i++) {
      for (int j = 0; j < (int)n; j++) {
        rec[q][i][j] = INF;
        for (int k = 0; k < (int)n; k++) {
          rec[q][i][j] = min(rec[q][i][j], rec[q / 2][i][k] + rec[q / 2][k][j]);
        }
      }
    }
  }
  for (int i = 0; i < (int)r; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    c = min(c, 60);
    cout << solve(a, b, c + 1) << endl;
  }
  return 0;
}
