#include <bits/stdc++.h>
using namespace std;
const int maxN = 70, inf = 1000 * 1000 * 1000;
int n, m, r, k, s, t, a[maxN][maxN][maxN], b[maxN][maxN][maxN];
int main() {
  cin >> n >> m >> r;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      b[0][i][j] = inf;
    }
  }
  for (int h = 0; h < m; ++h) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> a[h][i][j];
      }
    }
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          a[h][i][j] = min(a[h][i][j], a[h][i][k] + a[h][k][j]);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        b[0][i][j] = min(a[h][i][j], b[0][i][j]);
      }
    }
  }
  for (int h = 1; h <= n; ++h) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        b[h][i][j] = inf;
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k) {
          b[h][i][j] = min(b[h][i][j], b[h - 1][i][k] + b[0][k][j]);
        }
      }
    }
  }
  for (int i = 0; i < r; ++i) {
    cin >> s >> t >> k;
    cout << b[min(n, k)][s - 1][t - 1] << endl;
  }
  return 0;
}
