#include <bits/stdc++.h>
const double eps = 1e-10;
using namespace std;
using ul = unsigned long long;
using PII = pair<int, int>;
const int NN = 62;
const int NZ = 1111;
const int MM = 151;
const int need = (1 << 30) - 1;
int car[NN][NN][NN];
int n, m, a, b, c;
int r;
int dp[NN][NN][NN];
int wona[NN][NN];
int main() {
  scanf("%d %d %d", &n, &m, &r);
  for (int x = 1; x <= m; x++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        scanf("%d", &car[x][i][j]);
      }
    }
  }
  for (int x = 1; x <= m; x++) {
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          car[x][i][j] = min(car[x][i][j], car[x][i][k] + car[x][k][j]);
        }
      }
    }
  }
  for (int i = 1; i <= 62; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        dp[i][j][k] = 100000000000;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      wona[i][j] = 100000000000;
    }
  }
  for (int x = 1; x <= m; x++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        wona[i][j] = min(wona[i][j], car[x][i][j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[1][i][j] = wona[i][j];
    }
  }
  for (int c = 2; c <= 60; c++) {
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          dp[c][i][j] = min(dp[c][i][j], dp[c - 1][i][k] + dp[1][k][j]);
        }
      }
    }
  }
  for (int i = 0; i < r; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%d\n", dp[min(c + 1, 60)][a][b]);
  }
  return 0;
  system("pause");
}
