Given a matrix A and a matrix B, their **Kronecker product** C = A tensor B, also called their matrix direct product, is an matrix.

A tensor B = |a_{11}B a_{12}B| |a_{11}b_{11} a_{11}b_{12} a_{12}b_{11} a_{12}b_{12}|

|a_{21}B a_{22}B| = |a_{11}b_{21} a_{11}b_{22} a_{12}b_{21} a_{12}b_{22}|

|a_{11}b_{31} a_{11}b_{32} a_{12}b_{31} a_{12}b_{32}|

|a_{21}b_{11} a_{21}b_{12} a_{22}b_{11} a_{22}b_{12}|

|a_{21}b_{21} a_{21}b_{22} a_{22}b_{21} a_{22}b_{22}|

|a_{21}b_{31} a_{21}b_{32} a_{22}b_{31} a_{22}b_{32}|

**INPUT:** The first line consists of an integer T i.e. the number of test cases. The first line of each test case contains Four Integer m, n, p, q denoting the size of the Matrix. Here (m, n ) denoting the size of first and (p, q ) denoting the size of the second matrix. Next **m** lines contain **n** integers separated by space and another **P** lines contain **q **integers also separated by space.

**OUTPUT: **For each test case in a new line output will be the space-separated values of the matrix C[][].

**Constraints:**

1<=T<=50

1 <= m , n , p , q <= 20

1<= A[i][j] , B[i][j] <= 100

**Example:**

**Input : ** 1
2 2 2 2
1 2
3 4
0 5
6 7
**Output: ** 0 5 0 10
6 7 12 14
0 15 0 20
18 21 24 28

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.