#include <bits/stdc++.h>
int g[60][60][60];
int f[60][60][60];
int n, m;
int res[60][60][60];
void floyd() {
  int i, j, k, l;
  for (l = 0; l < m; l++)
    for (k = 0; k < n; k++)
      for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
          if (f[l][i][j] > f[l][i][k] + f[l][k][j])
            f[l][i][j] = f[l][i][k] + f[l][k][j];
}
void calc() {
  int i, j, k, ch;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) res[0][i][j] = 100000000;
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      for (k = 0; k < n; k++)
        if (f[i][j][k] < res[0][j][k]) res[0][j][k] = f[i][j][k];
  for (ch = 1; ch < n; ch++) {
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++) res[ch][i][j] = 100000000;
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        for (k = 0; k < n; k++) {
          if (res[ch][i][j] > res[ch - 1][i][k] + res[0][k][j])
            res[ch][i][j] = res[ch - 1][i][k] + res[0][k][j];
        }
  }
}
int main() {
  int i, j, k, r, from, to, maks;
  scanf("%d %d %d", &n, &m, &r);
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      for (k = 0; k < n; k++) scanf("%d", &g[i][j][k]), f[i][j][k] = g[i][j][k];
  floyd();
  calc();
  while (r--) {
    scanf("%d %d %d", &from, &to, &maks);
    if (maks >= n) maks = n - 1;
    printf("%d\n", res[maks][from - 1][to - 1]);
  }
  return 0;
}
