#include <bits/stdc++.h>
using namespace std;
const int maxn = 60 + 10;
int n, m, r;
int dis[maxn][maxn][maxn];
int w[maxn][maxn][maxn];
int main() {
  cin >> n >> m >> r;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= n; l++) cin >> w[j][l][i];
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= n; l++)
        for (int h = 1; h <= n; h++)
          w[l][h][i] = min(w[l][h][i], w[l][j][i] + w[j][h][i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= m; l++) {
        if (l == 1)
          dis[i][j][0] = w[i][j][l];
        else
          dis[i][j][0] = min(dis[i][j][0], w[i][j][l]);
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int l = 1; l <= n; l++)
        for (int h = 1; h <= n; h++) {
          if (j == 1)
            dis[l][h][i] = dis[l][j][0] + dis[j][h][i - 1];
          else
            dis[l][h][i] = min(dis[l][h][i], dis[l][j][0] + dis[j][h][i - 1]);
        }
  for (int i = 1; i <= r; i++) {
    int s, t, k;
    cin >> s >> t >> k;
    cout << dis[s][t][min(n, k)] << endl;
  }
  return 0;
}
