Product of Products

1012
Tempo Limite: 10 | Nível: 2

Descrição

Our company sells various products and we need to sum both the cost involved as well as the profit in this market. The input data is defined in two matrices, one indicating the products sold per month and another indicating the cost and profit per unit associated with each product. We need to produce a similar matrix containing the aggregate cost of the products sold, together with the profit. The Figure 1 illustrates a case where we have three different pieces and three months, with its result.

product of products image


Entrada

The input have many test cases. Initially, a N value is informed, indicating the quantity of test cases to be processed. Each test case starts with two integers P (0< P<=20) and M (0<M<=12) indicating, respectively, the quantity of sold products and the months to be considered. Next, two matrices must be read, the first containing M rows with P integers Q (0<=Q<=100), separated by a single white space, indicating the sold products sold in each month and the second containing P rows with two integers C and L (0<=C, L <=25) in each row, indicating respectively the cost and profit by unit of each product.


Saída

For each test case, print the number of the test case, as shown in the examples, followed by the matrix containing M rows, each one with two integers, that represents the total cost and profit of each month.


Exemplos de Entrada Exemplos de Saída

2
3 3
1 2 3
4 5 6
7 8 9
1 0
2 1
4 2
5 12
25 18 32 38 49
64 92 62 52 67
1 39 83 62 43
99 88 89 74 45
33 89 87 73 13
69 77 62 7 15
9 46 15 77 87
3 57 77 95 48
86 70 93 78 95
22 53 49 49 55
60 97 26 65 73
32 95 63 13 100
13 14
18 20
21 14
6 25
16 16

Case 1:
17 8
38 17
59 26
Case 2:
2333 2892
5174 5976
3518 4194
5904 6962
4504 5493
3867 3789
3114 4573
4020 5403
6319 7376
3443 4159
4630 5937
5127 5155

Efetue Login ou Cadastre-se para submeter uma solução.



Criado por Antonio Cesar de Barros Munari (Fatec Sorocaba) | Adaptado por erich.rodriguesf | Competição: Interfatecs 2014 1ª fase