#include <bits/stdc++.h>
using namespace std;
int n, m, r;
int len[61][61][61];
int dp[1003][61][61];
int tmp[61][61][61];
int d[61][61];
void floyd(int car) {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        tmp[i][j][k] = (1 << 29);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      tmp[0][i][j] = len[car][i][j];
    }
  }
  for (int len = 1; len <= n; len++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        tmp[len][i][j] =
            min(tmp[len - 1][i][len - 1] + tmp[len - 1][len - 1][j],
                tmp[len - 1][i][j]);
      }
    }
  }
}
void allPair() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = (1 << 29);
    }
  }
  for (int car = 0; car < m; car++) {
    floyd(car);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], tmp[n][i][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      dp[0][i][k] = d[i][k];
    }
  }
  for (int i = 1; i <= 1003; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        dp[i][j][k] = (1 << 29);
      }
    }
  }
}
int solve() {
  int start, destination, limit;
  scanf("%d %d %d", &start, &destination, &limit);
  start--;
  destination--;
  if (dp[limit][start][destination] < (1 << 29)) {
    printf("%d\n", dp[limit][start][destination]);
    return 0;
  }
  for (int lim = 1; lim <= limit; lim++) {
    if (dp[lim][start][destination] < (1 << 29)) continue;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          dp[lim][i][j] = min(dp[lim][i][j], dp[lim - 1][i][k] + dp[0][k][j]);
        }
      }
    }
  }
  printf("%d\n", dp[limit][start][destination]);
  return 0;
}
int main() {
  scanf("%d %d %d", &n, &m, &r);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        scanf("%d", &len[i][j][k]);
      }
    }
  }
  allPair();
  for (int i = 0; i < r; i++) {
    solve();
  }
  return 0;
}
