#include <bits/stdc++.h>
using namespace std;
inline int lowbit(int n) { return n & (-n); }
int dp[66][66][66];
int dis[66][66][66];
int to[66][66];
int main() {
  int n, m, r;
  for (; cin >> n >> m >> r;) {
    for (int i = 1; i <= m; ++i) {
      for (int j = 1; j <= n; ++j) {
        for (int k = 1; k <= n; ++k) {
          int x;
          scanf("%d", &x);
          dis[i][j][k] = x;
        }
      }
    }
    for (int i = 1; i <= m; ++i) {
      for (int p = 1; p <= n; ++p) {
        for (int j = 1; j <= n; ++j) {
          for (int k = 1; k <= n; ++k) {
            dis[i][j][k] = min(dis[i][j][k], dis[i][j][p] + dis[i][p][k]);
          }
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        to[i][j] = 0x3f3f3f3f;
        for (int k = 1; k <= m; ++k) {
          to[i][j] = min(to[i][j], dis[k][i][j]);
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        dp[0][i][j] = 0x3f3f3f3f;
        for (int k = 1; k <= m; ++k) {
          dp[0][i][j] = min(dp[0][i][j], dis[k][i][j]);
        }
      }
    }
    for (int i = 1; i <= n - 1; ++i) {
      for (int j = 1; j <= n; ++j) {
        for (int k = 1; k <= n; ++k) {
          dp[i][j][k] = dp[i - 1][j][k];
        }
      }
      for (int q = 1; q <= n; ++q) {
        for (int j = 1; j <= n; ++j) {
          for (int k = 1; k <= n; ++k) {
            dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][q] + to[q][k]);
          }
        }
      }
    }
    for (int i = 1; i <= r; ++i) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      if (z >= n) z = n - 1;
      printf("%d\n", dp[z][x][y]);
    }
  }
  return 0;
}
