#include <bits/stdc++.h>
using namespace std;
int n, m, r, u, v, K;
int E[60][60][60];
int e[61][60][60];
int main() {
  scanf("%d%d%d", &n, &m, &r);
  memset(e, 0x3f, sizeof(e));
  for (int c = 0; c < m; ++c) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        scanf("%d", &E[c][i][j]);
      }
    }
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          E[c][i][j] = min(E[c][i][j], E[c][i][k] + E[c][k][j]);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        e[0][i][j] = min(e[0][i][j], E[c][i][j]);
      }
    }
  }
  for (int l = 1; l <= n; ++l) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        e[l][i][j] = e[l - 1][i][j];
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k) {
          e[l][i][j] = min(e[l][i][j], e[l - 1][i][k] + e[0][k][j]);
        }
      }
    }
  }
  for (int i = 0; i < r; ++i) {
    scanf("%d%d%d", &u, &v, &K);
    K = min(K, n);
    printf("%d\n", e[K][--u][--v]);
  }
  return 0;
}
