{"raw_statement":[{"iden":"statement","content":"In computing, JPEG is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography . The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality,and JPEG typically achieves 10:1 compression with little perceptible loss in image quality. Entropy coding is a special form of lossless data compression. It involves arranging the image components in a \"zigzag\" order employing run-length encoding (RLE) algorithm that groups similar frequencies together, inserting length coding zeros, and then using Huffman coding on what is left. \n\nNow i am so busy ,so i will give you a  square matrix that represents pixel intensities of the image. \n\nYour task is simple: reconstruct the image so that the value in the ith row and jth column of the resulting image is the value of the (i * N + j)th pixel visited in the zigzag sequence .\n\nYour program will be tested on one or more test cases. The first line of the input contains a single integer *T* (1  ≤  *T*  ≤  100) the number of test cases. Followed by *T* test cases. \n\nEach test case consists of *N+1* lines. The first line contains an integer *N* (2  ≤  *N*  ≤  100). The next lines consists of an  squared pixel matrix.\n\nFor each test case print the required transformed matrix. \n\n"},{"iden":"input","content":"Your program will be tested on one or more test cases. The first line of the input contains a single integer *T* (1  ≤  *T*  ≤  100) the number of test cases. Followed by *T* test cases. Each test case consists of *N+1* lines. The first line contains an integer *N* (2  ≤  *N*  ≤  100). The next lines consists of an  squared pixel matrix."},{"iden":"output","content":"For each test case print the required transformed matrix. "},{"iden":"examples","content":"Input151 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output1 2 6 11 7 3 4 8 12 16 21 17 13 9 5 10 14 18 22 23 19 15 20 24 25 "}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ N_k \\in \\mathbb{Z} $ denote the side length of the square matrix.  \n- Let $ M_k = (m_{i,j}^{(k)})_{i,j=1}^{N_k} $ be the input $ N_k \\times N_k $ matrix of pixel intensities.  \n- Let $ P_k = (p_1^{(k)}, p_2^{(k)}, \\dots, p_{N_k^2}^{(k)}) $ be the zigzag traversal of $ M_k $, where $ p_\\ell^{(k)} $ is the $ \\ell $-th pixel visited in zigzag order.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 100 $  \n2. For each $ k \\in \\{1, \\dots, T\\} $:  \n   - $ 2 \\le N_k \\le 100 $  \n   - $ m_{i,j}^{(k)} \\in \\mathbb{R} $ (pixel intensities, unspecified domain)  \n\n**Objective**  \nFor each test case $ k $, construct the output matrix $ R_k = (r_{i,j}^{(k)})_{i,j=1}^{N_k} $ such that:  \n$$\nr_{i,j}^{(k)} = p_{i \\cdot N_k + j}^{(k)} \\quad \\text{for all } i,j \\in \\{1, \\dots, N_k\\}\n$$  \nwhere $ p_{i \\cdot N_k + j}^{(k)} $ is the pixel value at position $ i \\cdot N_k + j $ in the zigzag sequence of $ M_k $.  \n\n*(Note: Indexing assumes 1-based row/column indices and 1-based zigzag sequence indexing.)*","simple_statement":"Given a square matrix of size N×N, reorder its elements according to the zigzag scan pattern, then reshape the flattened zigzag sequence back into an N×N matrix row by row. Print the resulting matrix.","has_page_source":false}