Takeshi's Revenge

0

0 votes
Problem

Count Takeshi is back. He wants to take revenge for his defeat last time. To make the task more difficult, he now made a 3-D maze. On each level there are M rows, each row has N compartments; and there are K such levels( or floors). Therefore, there are a total of K X M X N compartments. Each compartment has a predetermined number of coins, denoted by coins(k,i,j) (k denoting the level number, I denoting the row number and j denoting the compartment number).

Count Takeshi will give the participant sumcoins(k,i,j) for all 1<=k<=K, 1<=i<=M and 1<=j<=N. sumcoins(k,i,j) contains the sum of number of coins in all the compartments (a,b,c) such that a>k or b>i or c>j. Your job is to find the number of coins in each compartment.

INPUT:

The first line contains the number of test cases T. T test cases follow. The first line of each test case contains four integers K M N and C (the total number of coins). Now, follow K squares, each of M X N dimensions. The first square will contain sumcoins(1,i,j) (for 1<=i<=M and 1<=j<=N.), the second square contains sumcoins(2,i,j) for all i and j and so on …

The first line of first square will contain N integer denoting sumcoins(1,1,j) (1<=j<=N), second line of the first square will contain N numbers denoting sumcoins(1,2,j) (1<=j<=N), the first line of the second square will contain N numbers denoting sumcoins(2,1,j) (1<=j<=N) and so on...

In other words, there are K X M lines. Each contain N numbers. The first line contains the number of coins in the compartment (1,1,1), (1,1,2), (1,1,3)… (1,1,N). The second line contains the number of coins in the compartment (1,2,1),(1,2,2),….(1,2,N). The (M+1)th line contains the number of coins in the compartments (2,1,1),(2,1,2),…,(2,1,N) and so on.

OUTPUT:

For each test case output the actual number of coins in each compartment in the same way as the input. That is, output K squares, each of dimension M X N. The kth square will denote the number of coins in the kth level (1<=k<=K).

The first line of each square will contain N numbers denoting the number of coins in the first row of that level, and the second line of each square will contain N numbers denoting the number of coins in the second row of that level and so on.

In other words, again there will be K X M lines. With each line having N integers. The first line having the numbers of the first row of first level, second line having numbers of second row of first level, M+1 th line having numbers of first row of second level and so on..

CONSTRAINTS:

1<=K,M,N<=100

1<=C<=10^9

Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?