#include <bits/stdc++.h>
using namespace std;
int insig;
void Out(vector<int> x) {
  for (int i = 0; i < x.size(); i++) {
    cout << x[i] << " ";
  }
  cout << endl;
}
int N, M, R;
vector<vector<vector<int> > > c;
vector<vector<int> > best;
vector<vector<vector<int> > > dp;
int f(int a, int b, int k) {
  if (k < 0) {
    return 10000000000LL;
  }
  if (k > N - 2) {
    return f(a, b, N - 2);
  }
  if (dp[a][b][k] >= 0) {
    return dp[a][b][k];
  }
  int ans = 10000000000LL;
  for (int i = 0; i < N; i++) {
    ans = min(ans, best[a][i] + f(i, b, k - 1));
  }
  dp[a][b][k] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M >> R;
  vector<int> xx;
  vector<vector<int> > xxx;
  for (int i = 0; i < N; i++) {
    xx.push_back(0);
  }
  for (int i = 0; i < N; i++) {
    xxx.push_back(xx);
  }
  for (int i = 0; i < M; i++) {
    c.push_back(xxx);
  }
  for (int i = 0; i < M; i++) {
    for (int a = 0; a < N; a++) {
      for (int b = 0; b < N; b++) {
        cin >> c[i][a][b];
      }
    }
  }
  for (int m = 0; m < M; m++) {
    for (int n = 0; n < N; n++) {
      for (int a = 0; a < N; a++) {
        for (int b = 0; b < N; b++) {
          c[m][a][b] = min(c[m][a][b], c[m][a][n] + c[m][n][b]);
        }
      }
    }
  }
  xx.clear();
  for (int i = 0; i < N; i++) {
    xx.push_back(0LL);
  }
  for (int i = 0; i < N; i++) {
    best.push_back(xx);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      best[i][j] = 10000000000LL;
    }
  }
  for (int i = 0; i < M; i++) {
    for (int a = 0; a < N; a++) {
      for (int b = 0; b < N; b++) {
        best[a][b] = min(best[a][b], c[i][a][b]);
      }
    }
  }
  xx.clear();
  xxx.clear();
  for (int i = 0; i < N - 1; i++) {
    xx.push_back(-1);
  }
  for (int i = 0; i < N; i++) {
    xxx.push_back(xx);
  }
  for (int i = 0; i < N; i++) {
    dp.push_back(xxx);
  }
  for (int a = 0; a < N; a++) {
    for (int b = 0; b < N; b++) {
      dp[a][b][0] = best[a][b];
    }
  }
  for (int i = 0; i < R; i++) {
    int s, t, k;
    cin >> s >> t >> k;
    s--;
    t--;
    cout << f(s, t, k) << "\n";
  }
  return 0;
}
