#include <bits/stdc++.h>
using namespace std;
const int N = 70;
long long int a[N][N][N], m[N], mark[N], dis[N][N], dp[N][N][N];
vector<int> e[N];
const long long inf = 1000 * 1000 * 1000 + 10;
int main() {
  int n, m, r;
  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 >> a[i][j][k];
      }
    }
  }
  for (int i = 0; i < 70; i++) {
    for (int j = 0; j < 70; j++) {
      for (int k = 0; k < 70; k++) {
        dp[i][j][k] = inf;
      }
    }
  }
  for (int car = 0; car < m; car++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dis[i][j] = a[car][i][j];
      }
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dp[0][i][j] = min(dp[0][i][j], dis[i][j]);
      }
    }
  }
  for (int tt = 1; tt < 70; tt++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          dp[tt][i][j] = min(dp[tt][i][j], min(dp[tt - 1][i][j],
                                               dp[0][i][k] + dp[tt - 1][k][j]));
        }
      }
    }
  }
  for (int i = 0; i < r; i++) {
    int x, y;
    cin >> x >> y;
    int kk;
    cin >> kk;
    kk = min(kk, 69);
    cout << dp[kk][x - 1][y - 1] << "\n";
  }
}
