#include <bits/stdc++.h>
int n, m, s, t, k, i, j, u, r;
int a[60][60][61];
int d[60][60][60];
int min(int a, int b) { return a < b ? a : b; }
int main(void) {
  scanf("%d %d %d", &n, &m, &r);
  for (u = 0; u < m; ++u)
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j) scanf("%d", &d[i][j][u]);
  for (u = 0; u < m; ++u)
    for (k = 0; k < n; ++k)
      for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
          if (i != j && i != k && j != k)
            d[i][j][u] = min(d[i][j][u], d[i][k][u] + d[k][j][u]);
  for (i = 0; i < n; ++i)
    for (j = 0; j < n; ++j) {
      a[i][j][0] = d[i][j][0];
      for (u = 1; u < m; ++u) a[i][j][0] = min(a[i][j][0], d[i][j][u]);
    }
  for (u = 1; u <= n; ++u) {
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j) a[i][j][u] = a[i][j][u - 1];
    for (k = 0; k < n; ++k)
      for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
          if (i != j && j != k && i != k)
            a[i][j][u] = min(a[i][j][u], a[i][k][u - 1] + a[k][j][0]);
  }
  for (i = 0; i < r; ++i) {
    scanf("%d %d %d", &s, &t, &k);
    printf("%d\n", a[s - 1][t - 1][min(n, k)]);
  }
  exit(0);
}
