{"problem":{"name":"B. Array Reconstructing","description":{"content":"You are given an array a consisting of n elements a1, a2, ..., an. Array a has a special property, which is:  You are given the array a with some lost elements from it, each lost element is replaced ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10153B"},"statements":[{"statement_type":"Markdown","content":"You are given an array a consisting of n elements a1, a2, ..., an. Array a has a special property, which is: \n\nYou are given the array a with some lost elements from it, each lost element is replaced by -1. Your task is to find all the lost elements again, can you?\n\nThe first line contains an integer T, where T is the number of test cases.\n\nThe first line of each test case contains two integers n and m (1 ≤ n ≤ 1000) (1 ≤ m ≤ 109), where n is the size of the array, and m is the described modulus in the problem statement.\n\nThe second line of each test case contains n integers a1, a2, ..., an ( - 1 ≤ ai < m), giving the array a. If the ith element is lost, then ai will be -1. Otherwise, ai will be a non-negative integer less than m.\n\nIt is guaranteed that the input is correct, and there is at least one non-lost element in the given array.\n\nFor each test case, print a single line containing n integers a1, a2, ..., an, giving the array a after finding all the lost elements.\n\nIt is guaranteed that an answer exists for the given input.\n\nAs input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.\n\n## Input\n\nThe first line contains an integer T, where T is the number of test cases.The first line of each test case contains two integers n and m (1 ≤ n ≤ 1000) (1 ≤ m ≤ 109), where n is the size of the array, and m is the described modulus in the problem statement.The second line of each test case contains n integers a1, a2, ..., an ( - 1 ≤ ai < m), giving the array a. If the ith element is lost, then ai will be -1. Otherwise, ai will be a non-negative integer less than m.It is guaranteed that the input is correct, and there is at least one non-lost element in the given array.\n\n## Output\n\nFor each test case, print a single line containing n integers a1, a2, ..., an, giving the array a after finding all the lost elements.It is guaranteed that an answer exists for the given input.\n\n[samples]\n\n## Note\n\nAs input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use _scanf/printf_ instead of _cin/cout_ in C++, prefer to use _BufferedReader/PrintWriter_ instead of _Scanner/System.out_ in Java.","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} $ be the length of the array.  \n- Let $ m_k \\in \\mathbb{Z} $ be the modulus.  \n- Let $ A_k = (a_{k,1}, a_{k,2}, \\dots, a_{k,n_k}) $ be the array, where each $ a_{k,i} \\in \\{-1\\} \\cup \\{0, 1, \\dots, m_k - 1\\} $.  \n- Let $ I_k^{\\text{known}} = \\{ i \\in \\{1, \\dots, n_k\\} \\mid a_{k,i} \\ne -1 \\} $ be the indices of known elements.  \n- Let $ I_k^{\\text{lost}} = \\{ i \\in \\{1, \\dots, n_k\\} \\mid a_{k,i} = -1 \\} $ be the indices of lost elements.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 1000 $  \n2. For each $ k \\in \\{1, \\dots, T\\} $:  \n   - $ 1 \\le n_k \\le 1000 $  \n   - $ 1 \\le m_k \\le 10^9 $  \n   - $ -1 \\le a_{k,i} < m_k $ for all $ i \\in \\{1, \\dots, n_k\\} $  \n   - $ I_k^{\\text{known}} \\ne \\emptyset $  \n\n**Objective**  \nReconstruct $ A_k $ by replacing each $ a_{k,i} = -1 $ with a value $ x_i \\in \\{0, 1, \\dots, m_k - 1\\} $ such that the entire array satisfies the unspecified \"special property\" (implied to be periodicity or congruence modulo $ m_k $, but not formally defined).  \n**Note**: Since the \"special property\" is not mathematically defined in the problem, the reconstruction objective cannot be formally specified beyond:  \n> Find $ A_k' = (a_{k,1}', \\dots, a_{k,n_k}') $ such that $ a_{k,i}' = a_{k,i} $ for $ i \\in I_k^{\\text{known}} $, and $ a_{k,i}' \\in \\{0, 1, \\dots, m_k - 1\\} $ for $ i \\in I_k^{\\text{lost}} $, and the array satisfies the (unstated) property that guarantees a unique solution.  \n\n**Output**  \nFor each test case $ k $, output $ A_k' $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10153B","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}