#include <bits/stdc++.h>
using namespace std;
int m[63][63], d[63][63], a[63][63], v[63][63][63];
int main() {
  int i, j, l, k, w, n;
  for (scanf("%d%d%d", &n, &l, &w), i = 0; i < n; i++)
    for (j = 0; j < n; a[i][j] = 1100000000, j++)
      ;
  for (; l--;) {
    for (i = 0; i < n; i++)
      for (j = 0; j < n; scanf("%d", &m[i][j]), j++)
        ;
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        for (k = 0; k < n; k++)
          if (m[i][j] + m[k][i] < m[k][j]) m[k][j] = m[i][j] + m[k][i];
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        if (m[i][j] < a[i][j]) a[i][j] = m[i][j];
  }
  for (i = 0; i < n; i++)
    for (j = 0; j < n; v[0][i][j] = a[i][j], j++)
      ;
  for (k = 1; k < n; k++)
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        for (v[k][i][j] = v[k - 1][i][j], l = 0; l < n; l++)
          if (v[k - 1][i][l] + a[l][j] < v[k][i][j])
            v[k][i][j] = v[k - 1][i][l] + a[l][j];
  for (; w--;) {
    scanf("%d%d%d", &i, &j, &k);
    if (k >= n) k = n - 1;
    printf("%d\n", v[k][i - 1][j - 1]);
  }
  return 0;
}
