#include <bits/stdc++.h>
using namespace std;
vector<int> v[70];
int d[70][70][70];
struct node {
  int c, num;
};
priority_queue<node> p;
bool operator<(const node ax, const node bx) { return ax.num > bx.num; }
void start(int n, int m) {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        d[i][j][k] = 1e9;
      }
    }
  }
}
int dis[70][70];
int dp[70][70][70];
int main() {
  int n, m, r;
  scanf("%d%d%d", &n, &m, &r);
  start(n, m);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        int x;
        scanf("%d", &x);
        dis[j][k] = x;
      }
    }
    for (int j = 1; j <= n; j++) {
      p.push(node{j, 0});
      d[i][j][j] = 0;
      while (p.size()) {
        node t = p.top();
        int head = t.c;
        int distance = t.num;
        for (int k = 1; k <= n; k++) {
          int newdis = dis[head][k] + distance;
          if (newdis < d[i][j][k]) {
            d[i][j][k] = newdis;
            p.push(node{k, newdis});
          }
        }
        p.pop();
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        dp[i][j][k] = 1e9;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= m; k++) {
        dp[i][j][0] = min(d[k][i][j], dp[i][j][0]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        for (int l = 1; l <= n; l++) {
          dp[k][l][i] = min(dp[k][l][i], dp[k][j][i - 1] + dp[j][l][0]);
        }
      }
    }
  }
  for (int i = 1; i <= r; i++) {
    int si, ti, ki;
    scanf("%d%d%d", &si, &ti, &ki);
    if (ki >= n)
      printf("%d\n", dp[si][ti][n]);
    else {
      printf("%d\n", dp[si][ti][ki]);
    }
  }
  return 0;
}
