#include<stdio.h>#include<math.h>int main(){ int t; int m, n, k; int num[60][60]; scanf("%d",&t); while (t--) { scanf("%d%d%d",&m,&n,&k); for (int i = 1; i <= m; i++) { for (int j = 0; j < n; j++) { scanf("%d",&num[i][j]); } } int max = 0, x = 0, y = 0; int px=0, py=0; int flag = 0; int total = 0; int ret = 0; while (1) { for (int i = 1; i <= m; i++) { for (int j = 0; j < n; j++) { if (num[i][j] > max) { max = num[i][j]; x = i; y = j; } } } if (flag == 0) { px = 0; py = y; flag = 1; } if (total + abs(x - px) + abs(y - py) + 1 + x <= k) { ret += max; total += abs(x - px) + abs(y - py) + 1; px = x; py = y; num[x][y] = -1; max = 0; } else { PRintf("%d/n",ret); break; } } } return 0;}