Matrix Multiplication Calculator

Read pairs of matrices with dimension lines, multiply them when the inner dimensions match, and print each result row wrapped in vertical bars, or print undefined.

Easy2ImplementationMatrixMathBrute forceNo attempts yetTime limit2sMemory limit512 MB

Problem

Matrix multiplication is a basic operation of linear algebra, with applications across mathematics, applied mathematics, computer graphics, physics, and engineering.

Two matrices can be multiplied only when their dimensions are compatible: the number of columns of the first matrix must equal the number of rows of the second matrix.

If A=[aij]A = [a_{ij}] is an m×nm \times n matrix and B=[bij]B = [b_{ij}] is an n×qn \times q matrix, the product ABAB is an m×qm \times q matrix. The product ABAB is defined as the m×qm \times q matrix C=[cij]C = [c_{ij}] with

cij=k=1naikbkjc_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}

Build a matrix multiplication calculator that multiplies two given matrices and prints the result. If the matrices cannot be multiplied, print undefined.

Input

The input consists of several test cases. For each test case, the first line gives four positive integers M,N,P,QM, N, P, Q (1M,N,P,Q201 \le M, N, P, Q \le 20). MM and NN are the dimensions of matrix AA, while PP and QQ are the dimensions of matrix BB. The next MM lines hold matrix AA, followed by PP lines holding matrix BB. Each row lists its entries separated by single spaces. The input ends with a line 0 0 0 0, which is not processed.

Output

For each test case, print a line Case #x:, where xx is the case number starting from 11. On the following lines, print the result of the multiplication. When the product exists, print one row of the result matrix per line in the form | entries |, wrapped in | characters with entries separated by single spaces. When the matrices cannot be multiplied, print a single line undefined.