
The output you will see will be in sorted order.
Your order of output does not matter.
You can return your result in any order.
Input: ‘M’ = 2, ‘N’ = 2, ‘MAT’ = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]

Output: [1, 2, 3, 4, 5, 8, 9, 12, 13, 14, 15, 16]
If we traverse the matrix in clockwise order from the top left then it will be 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5. Which in output will be shown in sorted order which is 1, 2, 3, 4, 5, 8, 9, 12, 13, 14, 15, 16.

Referring to the image above, we are printing only the elements that lie on the boundary.
The first line will contain the integer 'T', denoting the number of test cases.
The first line of each test contains two integers ‘M’ and ‘N’ respectively.
The Next ‘M’ line contains ‘N’ elements denoting the matrix.
For each test case print the boundary elements.
You don't need to print anything. It has already been taken care of. Just implement the given function.
2 <= T <= 10
1 <= N, M <= 2000
Time Limit: 1 sec
We can traverse the whole matrix and print only those elements that are boundary elements and for all the other elements we can mark them as whitespace.
We can create a 2D matrix of size M*N initialized with ‘ ‘. We will traverse only the first row and last row and update the values with ‘MAT’ values of the corresponding also we will traverse the first column and last column and update the values of ‘ans’ with ‘MAT’ values.