시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 28 15 15 53.571%

문제

Matrix multiplication is a basic tool of linear algebra, and has numerous applications in many areas of mathematics, as well as in applied mathematics, computer graphics, physics, and engineering.

We can only multiply two matrices if their dimensions are compatible, which means the number of columns in the first matrix is the same as the number of rows in the second matrix.

If A = [aij] is an m×n matrix and B = [bij] is an n×q matrix, the product AB is an m×q matrix. The product AB is defined to be the m×q matrix C = [cij] such that

\[c_{ij} = \sum_{k=1}^{n}{a_{ik}b_{kj}\]

Your task is to design a matrix multiplication calculator to multiply two matrices and display the output. If the matrices cannot be multiplied, display "undefined"

입력

The input consists of a few test cases. For each test case, the first line of input is 4 positive integers, M, N, P and Q (1 ≤ M, N, P, Q ≤ 20). M and N represent the dimension of matrix A, while P and Q represent the dimension of matrix B. The following M lines consist of the data for matrix A followed by P lines that contains the data for matrix B as shown in the sample input. The test data ends when M, N, P and Q are 0.

출력

For each test case, the output contains a line in the format "Case #x:", where x is the case number (starting from 1). The following line(s) is the output of the matrix multiplication.

예제 입력 1

2 3 3 2
1 2 3
3 2 1
4 5
6 7
8 9
2 3 2 3
1 2 3
3 2 1
4 5 6
7 8 9
0 0 0 0

예제 출력 1

Case #1:
| 40 46 |
| 32 38 |
Case #2:
undefined