You are given a chocolate bar in the form of a grid consisting of N x M pieces of chocolate. Your task is to take out exactly ‘K’ pieces of chocolate by cutting the chocolate bar either horizontally or vertically. This operation will cost you the square of break length.
For example: If you have a chocolate bar of size 3x4, then you can cut horizontally and get two bars of the chocolate of size 1x4 and 2x4. The cost of this cut will be 4^2 = 16 or you can cut vertically and get two bars of the chocolate of size 3x1 and 3x3. The cost of this cut will be 3^2 = 9.
You are given ‘Q’ queries and for each query you need to find the minimum cost such that after all the cutting operations, exactly ‘K’ pieces are obtained from a chocolate of dimension N x M.
Note:
1.You can discard the remaining N x M - K pieces.
2.You do not need to print anything. It has already been taken care of by our driver code. Just implement the given function and return the minimum cost of cutting the chocolate bar to get exactly ‘K’ pieces of chocolate for each query.
Input Format:
The first line of the input contains an integer ‘Q’ denoting the number of queries.
The first line of each query contains three space-separated integer values ‘N’, ‘M’, ‘K’ denoting the dimensions of the chocolate bar and the number of pieces you want, respectively.
Output Format:
You need to print ‘Q’ lines, each line contains the output of each query which is an integer denoting the minimum total cost needed to break the chocolate bar, to make it possible to have K pieces of chocolate.
Constraints:
1 <= Q <= 10^4
1 <= N,M <= 30
1<= K <= min(NxM,50)
Time Limit: 1 sec