##### Canadian Computing Competition: 2005 Stage 1, Senior #3

Quantum computing is currently a hot topic in research. If they can be built, quantum computers will have the ability to perform certain computing tasks much faster than any computer in existence today. Fortunately, you won't need a quantum computer to do this question.

A fundamental concept in quantum computing is the idea of a quantum operation. A quantum operation can be essentially thought of as a matrix. Also, if you perform two quantum operations in parallel on separate quantum data, this can be thought of as a larger quantum operation. Thinking of these operations in terms of matrices again, the resulting matrix from performing two matrices in parallel is called the *tensor product* of the two matrices (using the symbol ). This is different than the normal product of matrices that you may have learned about.

In a tensor product, you are given two matrices (which are essentially two-dimensional arrays). We will call them and , and we will represent the individual elements of these two matrices this way:

Notice that the size of matrix is ( rows and columns), and the size of is .

The tensor product of these two matrices will be an matrix (with rows and columns) that looks like:

where simply indicates that each element in is being multiplied by .

Finally notice that the tensor product is not *commutative*, which means that changing the order of matrices may change the answer .

For more than two matrices, we will define , although it does not technically matter, since the tensor product is *associative*.

Your task is to compute and output the tensor product of two or more given matrices.

#### Input Specification

The first line of input will contain the number of matrices, , a positive integer. Then, there are blocks of lines describing the matrices in order.

In each block, the first line will contain two positive integers, and , separated by a space, indicating the number of rows and columns, respectively. Then, the next lines will denote the rows, in order. Each line will contain integers, separated by spaces.

#### Output Specification

The output (to the screen) will be 6 integers in the following order:

- the maximum element in the tensor product
- the minimum element in the tensor product
- the maximum row sum (i.e., sum of entries in each row)
- the minimum row sum
- the maximum column sum
- the minimum column sum

You may assume that the tensor product matrix will have no more than rows and no more than columns.

#### Sample Input 1

```
2
2 2
1 1
1 -1
2 2
1 0
0 1
```

#### Sample Output 1

```
1
-1
2
0
2
0
```

#### Tensor Product for Sample Input 1

```
1 0 1 0
0 1 0 1
1 0 -1 0
0 1 0 -1
```

#### Sample Input 2

```
3
2 2
1 0
0 3
2 2
1 1
1 -1
2 2
1 0
0 1
```

#### Sample Output 2

```
3
-3
6
0
6
0
```

#### Tensor Product for Sample Input 2

```
1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0
1 0 -1 0 0 0 0 0
0 1 0 -1 0 0 0 0
0 0 0 0 3 0 3 0
0 0 0 0 0 3 0 3
0 0 0 0 3 0 -3 0
0 0 0 0 0 3 0 -3
```

## Comments

When the first two paragraphs are a bunch of random words you don't understand!

What are the bounds on ?

Probably doesn't matter too much to the actual problem, considering best solutions are able to do 10 cases in 0.02s

"You may assume that the tensor product matrix will have no more than rows and no more than columns."

That doesn't necessarily put a bound on if matrices can be .

It should place a bound on the intended solution's size. having 10 matrices come together to form it would be only marginally less efficient than a single matrix.