33OJ
登录 注册

#P14217. [ICPC 2024 Kunming I] 两星级竞赛

[ICPC 2024 Kunming I] 两星级竞赛

Problem Description

For some reason, education experts are going to rate nn contests. The experts have already decided the rating of each contest, where the ii-th contest is rated as an sis_i-star contest.

It is said that each contest is rated according to mm attributes, where the jj-th attribute of the ii-th contest is denoted by pi,jp_{i, j}, and each attribute takes a value from 00 to kk (inclusive). The score of a contest is the sum of all its mm attributes. That is, letting viv_i denote the score of the ii-th contest, we have vi=∑j=1mpi,jv_i = \sum\limits_{j=1}^m p_{i, j}.

It looks more natural if a contest with more stars has a higher score. The experts require that for any two contests 1≤i,j≤n1 \le i, j \le n, if si>sjs_i > s_j, then vi>vjv_i > v_j must hold. Unfortunately, the experts forgot to collect the data of some (or even all) attributes of some contests. As the assistant of the experts, you are asked to fill in these missing attribute values so that the above restriction holds for any two contests.

Input Format

There are multiple test cases. The first line contains an integer TT denoting the number of test cases. For each test case:

The first line contains three integers nn, mm and kk (2≤n≤4×1052 \le n \le 4 \times 10^5, 1≤m≤4×1051 \le m \le 4 \times 10^5, n×m≤4×105n \times m \le 4 \times 10^5, 1≤k≤1091 \le k \le 10^9) denoting the number of contests, how many attributes each contest has, and the upper bound of the value of each attribute.

For the next nn lines, the ii-th line first contains an integer sis_i (1≤si≤1091 \le s_i \le 10^9) denoting the star rating of the ii-th contest. Then mm integers pi,1,pi,2,⋯ ,pi,mp_{i, 1}, p_{i, 2}, \cdots, p_{i, m} (−1≤pi,j≤k-1 \le p_{i, j} \le k) follow. If pi,j=−1p_{i, j} = -1, the value of the jj-th attribute of the ii-th contest is missing and you need to fill it in; otherwise, if pi,j≥0p_{i, j} \ge 0, the value of the jj-th attribute of the ii-th contest is given and you should not change it.

It is guaranteed that the sum of n×mn \times m over all test cases does not exceed 4×1054 \times 10^5.

Output Format

For each test case:

If it is possible to fill in all missing attribute values and satisfy the restriction, first output one line with Yes\texttt{Yes}. Then output nn lines, where the ii-th line contains mm integers qi,1,qi,2,⋯ ,qi,mq_{i, 1}, q_{i, 2}, \cdots, q_{i, m} (0≤qi,j≤k0 \le q_{i, j} \le k) separated by single spaces, denoting the mm attribute values of the ii-th contest after filling. If pi,j=−1p_{i, j} = -1, then qi,jq_{i, j} is the value you filled in; otherwise, if pi,j≥0p_{i, j} \ge 0, then qi,j=pi,jq_{i, j} = p_{i, j}. If there are multiple answers, you may output any of them.

If the restriction cannot be satisfied, just output one line with No\texttt{No}.

5
3 4 5
5 1 3 -1 -1
2 -1 5 -1 5
3 3 -1 -1 4
2 3 10
10000 5 0 -1
1 10 10 10
2 3 10
10 1 2 3
100 4 5 6
2 3 10
100 1 2 3
10 4 5 6
2 3 10000
100 -1 -1 -1
1 -1 -1 -1
Yes
1 3 5 4
0 5 0 5
3 3 2 4
No
Yes
1 2 3
4 5 6
No
Yes
2024 5 26
11 45 14

Hint

For the second sample, even if we fill the only −1-1 with the maximum possible value 1010, the score of the first contest is only 1515, which is not greater than the score 3030 of the second contest.

Translated by QwenWork