#C5059. Crop Rotation Distribution
Crop Rotation Distribution
Crop Rotation Distribution
Farmer Joe wants to implement a cyclic crop rotation plan in his fields over several years. Given the number of fields, the number of years, and the initial crop type for each field, your task is to compute the crop distribution plan.
For a given field with an initial crop type \(c\) and a total of \(M\) years, the crop type in the \(j^{th}\) year (starting with \(j=0\)) will be \( (c + j) \mod M \). Output the plan for each test case: for every field, print a line containing \(M\) numbers representing the crop distribution over the years.
inputFormat
The first line of input contains a single integer (T), the number of test cases. Each test case consists of two lines:
- The first line contains two integers (F) and (M), where (F) is the number of fields and (M) is the number of years.
- The second line contains (F) space-separated integers, where the (i^{th}) integer denotes the initial crop type (c_i) for the (i^{th}) field.
It is guaranteed that the crop types are non-negative integers.
outputFormat
For each test case, output (F) lines. The (i^{th}) line should contain (M) space-separated integers corresponding to the crop rotation plan for field (i). The crop type for field (i) in year (j) is computed as ((c_i + j) \mod M).## sample
1
3 3
0 1 2
0 1 2
1 2 0
2 0 1
</p>