AT_abc433_e [ABC433E] Max Matrix 2

Description

You are given integers $ N,M $ , a sequence of $ N $ integers $ X=(X_1,X_2,\ldots,X_N) $ , and a sequence of $ M $ integers $ Y=(Y_1,Y_2,\ldots,Y_M) $ . Determine whether there exists an $ N $ row by $ M $ column integer matrix $ A=(A_{i,j}) $ $ (1\le i\le N,\ 1\le j\le M) $ that satisfies all of the following conditions, and if so, find one such matrix. - $ 1\le A_{i,j} \le N\times M $ - All $ N\times M $ elements of $ A_{i,j} $ are distinct. - $ \displaystyle \max_{1\le j\le M} A_{i,j} = X_i $ for $ i=1,2,\ldots,N $ . - $ \displaystyle \max_{1\le i\le N} A_{i,j} = Y_j $ for $ j=1,2,\ldots,M $ . You are given $ T $ test cases; solve each of them.

Input Format

The input is given from Standard Input in the following format: > $ T $ $ \text{case}_1 $ $ \text{case}_2 $ $ \vdots $ $ \text{case}_T $ Each test case is given in the following format: > $ N $ $ M $ $ X_1 $ $ X_2 $ $ \ldots $ $ X_N $ $ Y_1 $ $ Y_2 $ $ \ldots $ $ Y_M $

Output Format

Output the answers for the test cases in order, separated by newlines. For each test case, if there is no $ A $ that satisfies all the conditions, output `No`. Otherwise, output $ A $ that satisfies all the conditions in the following format: > Yes $ A_{1,1} $ $ A_{1,2} $ $ \ldots $ $ A_{1,M} $ $ A_{2,1} $ $ A_{2,2} $ $ \ldots $ $ A_{2,M} $ $ \vdots $ $ A_{N,1} $ $ A_{N,2} $ $ \ldots $ $ A_{N,M} $ If there are multiple $ A $ that satisfy the conditions, any of them will be accepted.

Explanation/Hint

### Sample Explanation 1 Consider the first test case. In the sample output, all elements of $ A $ are between $ 1 $ and $ 6 $ and are distinct, and furthermore, - $ \displaystyle \max_{1\le j\le 3} A_{1,j} =\max \lbrace 5,1,4\rbrace = 5 = X_1 $ - $ \displaystyle\max_{1\le j\le 3} A_{2,j} =\max \lbrace 2,3,6\rbrace = 6 = X_2 $ - $ \displaystyle\max_{1\le i\le 2} A_{i,1} =\max \lbrace 5,2\rbrace = 5 = Y_1 $ - $ \displaystyle\max_{1\le i\le 2} A_{i,2} =\max \lbrace 1,3\rbrace = 3 = Y_2 $ - $ \displaystyle\max_{1\le i\le 2} A_{i,3} =\max \lbrace 4,6\rbrace = 6 = Y_3 $ so all conditions are satisfied. Other outputs, such as the following, are also accepted. ``` Yes 5 3 1 4 2 6 ``` ### Constraints - $ 1\le T\le 10^5 $ - $ 1\le N,M $ - The sum of $ N\times M $ over all test cases is at most $ 2\times 10^5 $ . - $ 1\le X_i,Y_j\le N\times M $ - All input values are integers.