{"problem":{"name":"K. Jpeg","description":{"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, allowin","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":65536},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10094K"},"statements":[{"statement_type":"Markdown","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## Input\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. 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.\n\n## Output\n\nFor each test case print the required transformed matrix. \n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**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.)*","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10094K","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}