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