#include <bits/stdc++.h>
using namespace std;
int t[60][60][60];
int d[60][60][60];
int f[60][60][60];
int n, m;
int main() {
  int r;
  scanf("%d", &n);
  ;
  scanf("%d", &m);
  ;
  scanf("%d", &r);
  ;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) d[i][j][k] = 1000000000;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) {
        scanf("%d", &t[i][j][k]);
        ;
        if (j != k) d[i][j][k] = t[i][j][k];
      }
  for (int i = 0; i < m; i++)
    for (int x = 0; x < n; x++)
      for (int j = 0; j < n; j++)
        if (d[i][j][x] != 1000000000)
          for (int k = 0; k < n; k++)
            if (d[i][x][k] != 1000000000)
              if (d[i][j][k] > (d[i][j][x] + d[i][x][k]))
                d[i][j][k] = d[i][j][x] + d[i][x][k];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      f[i][j][0] = 1000000000;
      for (int k = 0; k < m; k++) f[i][j][0] = min(f[i][j][0], d[k][i][j]);
    }
  for (int k = 1; k <= n - 1; k++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        f[i][j][k] = f[i][j][k - 1];
        for (int x = 0; x < n; x++)
          f[i][j][k] = min(f[i][j][k], f[i][x][k - 1] + f[x][j][0]);
      }
  }
  int a, b, k;
  for (int i = 0; i < r; i++) {
    scanf("%d", &a);
    ;
    scanf("%d", &b);
    ;
    scanf("%d", &k);
    ;
    a--;
    b--;
    if (k >= n) k = n - 1;
    printf("%d\n", f[a][b][k]);
  }
  return 0;
}
