// Arup Guha
// 8/31/2013
// Solution to 2013 UCF Locals Problem: Sub Matrix Sum

import java.util.*;
import java.io.*;

public class sum {

	public static int NOSOLUTION = 1000000000;

	public static int r;
	public static int c;
	public static long target;
	public static long[][] grid;
	public static long[][] colSums;

	public static void main(String[] args) throws Exception {

		Scanner stdin = new Scanner(new File("sum.in"));
		int numCases = stdin.nextInt();

		// Go through cases.
		for (int loop=0; loop<numCases; loop++) {

			// Get input.
			r = stdin.nextInt();
			c = stdin.nextInt();
			target = stdin.nextLong();
			grid = new long[r][c];
			for (int i=0; i<r; i++)
				for (int j=0; j<c; j++)
					grid[i][j] = stdin.nextLong();
			grid = fixGrid(grid);

			// Get sums and solve.
			colSums = getColSums();
			System.out.println(solve());
		}

		stdin.close();

	}

	// Transposes the grid, if necessary so the resultant grid has fewer rows than columns.
	public static long[][] fixGrid(long[][] a) {

		if (a.length < a[0].length) return a;

		long[][] ans = new long[a[0].length][a.length];

		for (int i=0; i<ans.length; i++)
			for (int j=0; j<ans[0].length; j++)
				ans[i][j] = a[j][i];

		return ans;
	}

	// Calculates the running sums of each column from index 0.
	public static long[][] getColSums() {

		long[][] ans = new long[grid.length+1][grid[0].length];

		// Using a default row of zeros to make the subtraction trick easier.
		for (int i=0; i<ans[0].length; i++)
			ans[0][i] = 0;

		// Calculate all running column sums...
		for (int i=1; i<ans.length; i++)
			for (int j=0; j<ans[0].length; j++)
				ans[i][j] = ans[i-1][j] + grid[i-1][j];

		return ans;
	}

	public static long solve() {

		int best = NOSOLUTION;

		// Run a brute force over all pairs of starting and ending rows.
		for (int i=0; i<grid.length; i++) {
			for (int j=i; j<grid.length; j++) {

				// Keep these for easy recall.
				int n = grid[0].length;
				int curLength = j-i+1;

				// Store these rectangles (fixing rows i and j) in one column.
				long[] array = new long[n];
				for (int k=0; k<n; k++)
					array[k] = colSums[j+1][k] - colSums[i][k];

				// Run sort-of greedy algorithm in one dimension.
				pair[] stack = new pair[n];
				long curSum = 0;
				int curIndex = 0;
				int stackIndex = 0;

				// Iterate through sums.
				while (curIndex < n) {

					long oldCurSum = curSum;
					curSum += array[curIndex];

					// Cut this off, just like MCSS.
					if (curSum <= 0) {
						stackIndex = 0;
						curSum = 0;
						curIndex++;
						continue;
					}

					// First positive value, so add.
					else if (stackIndex == 0) {
						stack[stackIndex] = new pair(curIndex, oldCurSum);
						stackIndex++;
					}

					// Typical case that needs processing.
					else if (curSum > oldCurSum){

						pair tmp = new pair(curIndex, oldCurSum);

						// Pop off unnecessary states.
						while (stackIndex > 0 && stack[stackIndex-1].sum >= oldCurSum) stackIndex--;

						// Place this item.
						stack[stackIndex] = tmp;
						stackIndex++;
					}

					// Do our binary search.
					if (curSum >= target) {
						int bestIndex = binSearch(stack, stackIndex, curSum-target);
						int curWidth = curIndex - bestIndex + 1;
						if (curWidth*curLength < best)
							best = curWidth*curLength;
					}

					curIndex++;
				}

			}
		}

		if (best == NOSOLUTION) return -1;
		return best;
	}

	// Returns the maximum index in stack < len such that sum <= value.
	public static int binSearch(pair[] stack, int len, long value) {

		int low = 0, high = len-1;

		// Usual binary search, stopping one index short.
		while (low < high-1) {

			int mid = (low+high)/2;

			if (stack[mid].sum > value)
				high = mid-1;
			else
				low = mid;
		}

		// Just brute force this little bit.
		while (high > 0 && stack[high].sum > value) high--;

		// Return the index of this term.
		return stack[high].index;
	}
}

class pair {

	public int index;
	public long sum;

	public pair(int i, long s) {
		index = i;
		sum = s;
	}
}