#include <bits/stdc++.h>
int N, M, R;
int D[61][61][61];
int D_MINI[61][61];
int Find_max(int a, int b) {
  if (a > b) return a;
  return b;
}
int Find_min(int a, int b) {
  if (a > b) return b;
  return a;
}
int print(int t) {
  int i, j;
  if (t == 0) {
    for (i = 1; i <= N; i++) {
      for (j = 1; j <= N; j++) {
        printf("%d ", D_MINI[i][j]);
      }
      printf("\n");
    }
    printf("\n");
    return 0;
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      printf("%d ", D[t][i][j]);
    }
    printf("\n");
  }
  printf("\n");
  return 0;
}
void Put_D(int x) {
  int t, i, j;
  for (t = 1; t <= N; t++) {
    for (i = 1; i <= N; i++) {
      if (i == t) continue;
      for (j = 1; j <= N; j++) {
        if (i == j || t == j) continue;
        D[x][i][j] = Find_min(D[x][i][j], D[x][i][t] + D[x][t][j]);
      }
    }
  }
}
int Dy[1001][61][61];
int visit[61];
void Clean(int C) {
  int i, j;
  for (i = 1; i <= C; i++) {
    for (j = 1; j <= N; j++) {
    }
  }
}
void Dy_Find(int s, int e, int C) {
  int i, j, t, min;
  for (i = 1; i <= N; i++) {
    Dy[0][s][i] = D_MINI[s][i];
  }
  for (i = 1; i <= C; i++) {
    for (j = 1; j <= N; j++) {
      min = -1;
      for (t = 1; t <= N; t++) {
        if (min == -1)
          min = Dy[i - 1][s][t] + D_MINI[t][j];
        else
          min = Find_min(min, Dy[i - 1][s][t] + D_MINI[t][j]);
      }
      if (min != -1) Dy[i][s][j] = min;
    }
  }
}
int main() {
  int i, j, t, min;
  scanf("%d%d%d", &N, &M, &R);
  for (t = 1; t <= M; t++) {
    for (i = 1; i <= N; i++) {
      for (j = 1; j <= N; j++) {
        scanf("%d", &D[t][i][j]);
      }
    }
  }
  for (t = 1; t <= M; t++) {
    Put_D(t);
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      min = -1;
      for (t = 1; t <= M; t++) {
        if (min == -1)
          min = D[t][i][j];
        else
          min = Find_min(D[t][i][j], min);
      }
      D_MINI[i][j] = min;
    }
  }
  int si, ki, ti;
  for (i = 1; i <= R; i++) {
    min = -1;
    scanf("%d %d %d", &si, &ti, &ki);
    if (visit[si] == 0) Dy_Find(si, ti, 60);
    visit[si] = 1;
    if (ki > 60) ki = 60;
    for (j = 0; j <= ki; j++) {
      if (Dy[j][si][ti] == -1) continue;
      if (min == -1)
        min = Dy[j][si][ti];
      else
        min = Find_min(min, Dy[j][si][ti]);
    }
    printf("%d\n", min);
  }
  return 0;
}
