#include <bits/stdc++.h>
using namespace std;
const int maxn = 62;
const int maxr = 100010;
const int inf = 2047483647;
const int maxk = 1010;
int n, m, r, s, t, k;
int dis[maxn][maxn][maxn];
int dist[maxn][maxn][maxn];
int add[maxn][maxn];
int ans[maxn][maxn][maxk];
void floyed() {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dist[k][i][j] = inf;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      add[i][j] = inf;
    }
  }
  for (int t = 1; t <= m; t++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        cin >> dist[t][i][j];
      }
    }
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          dist[t][i][j] = min(dist[t][i][j], dist[t][i][k] + dist[t][k][j]);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        add[i][j] = min(add[i][j], dist[t][i][j]);
      }
    }
  }
}
void dp() {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int kk = 0; kk <= k; kk++) {
        ans[i][j][kk] = inf;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans[i][j][0] = add[i][j];
    }
  }
  for (int kk = 1; kk <= k; kk++) {
    for (int x = 1; x <= n; x++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          ans[i][j][kk] = min(ans[i][j][kk], ans[i][x][kk - 1] + add[x][j]);
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> r;
  floyed();
  k = 100;
  dp();
  while (r--) {
    cin >> s >> t >> k;
    cout << ans[s][t][min(k, 100)] << '\n';
  }
  return 0;
}
