


The sine wave for the matrix:-
1 2
3 4
will be [1, 3, 4, 2].
The first line contains an Integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains two integer values, 'N' and 'M,’ separated by a single space. They represent the 'rows' and 'columns,’ respectively, for the two-dimensional array/list ‘ARR’.
The next ‘N’ line contains an ‘M’ single-separated integer denoting the value of ‘ARR’.
For each test case, print the two-dimensional array/list ‘ARR’ elements in the sine wave order in a single line, separated by a single space.
Output for every test case will be printed in a separate line.
1 <= T <= 10
1 <= N <= 100
1 <= M <= 100
0 <= ARR[i][j] <= 100
Time Limit: 1sec
The basic idea of this approach is to print the elements row-wise. The elements are printed in two ways; top-down and bottom-up. It has been observed that the odd rows are printed in a bottom-up manner, and even ones are printed in a top-down manner. We will use two loops, the first loop will iterate through the number of columns, and the second loop will print the element row-wise.
Here is the algorithm: