{"problem":{"name":"B. Beautiful Now","description":{"content":"Anton has a positive integer n, however, it quite looks like a mess, so he wants to make it beautiful after k swaps of digits. Let the decimal representation of n as (x1x2... xm)10 satisfying that 1 ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10211B"},"statements":[{"statement_type":"Markdown","content":"Anton has a positive integer n, however, it quite looks like a mess, so he wants to make it beautiful after k swaps of digits.\n\nLet the decimal representation of n as (x1x2... xm)10 satisfying that 1 ≤ x1 ≤ 9, 0 ≤ xi ≤ 9 (2 ≤ i ≤ m), which means . In each swap, Anton can select two digits xi and xj (1 ≤ i ≤ j ≤ m) and then swap them if the integer after this swap has no leading zero.\n\nCould you please tell him the minimum integer and the maximum integer he can obtain after k swaps?\n\nThe first line contains one integer T, indicating the number of test cases.\n\nEach of the following T lines describes a test case and contains two space-separated integers n and k.\n\n1 ≤ T ≤ 100, 1 ≤ n, k ≤ 109.\n\nFor each test case, print in one line the minimum integer and the maximum integer which are separated by one space.\n\n## Input\n\nThe first line contains one integer T, indicating the number of test cases.Each of the following T lines describes a test case and contains two space-separated integers n and k.1 ≤ T ≤ 100, 1 ≤ n, k ≤ 109.\n\n## Output\n\nFor each test case, print in one line the minimum integer and the maximum integer which are separated by one space.\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 $ i \\in \\{1, \\dots, T\\} $:  \n- Let $ n_i \\in \\mathbb{Z}^+ $ be the positive integer, with decimal representation $ d_{i,1}d_{i,2}\\dots d_{i,m_i} $, where $ m_i = \\lfloor \\log_{10} n_i \\rfloor + 1 $, $ 1 \\leq d_{i,1} \\leq 9 $, and $ 0 \\leq d_{i,j} \\leq 9 $ for $ 2 \\leq j \\leq m_i $.  \n- Let $ k_i \\in \\mathbb{Z}^+ $ be the number of allowed digit swaps.  \n\n**Constraints**  \n1. $ 1 \\leq T \\leq 100 $  \n2. $ 1 \\leq n_i \\leq 10^9 $, so $ 1 \\leq m_i \\leq 10 $  \n3. $ 1 \\leq k_i \\leq 10^9 $  \n\n**Objective**  \nFor each test case $ i $, compute:  \n- $ \\min_i $: the lexicographically smallest integer obtainable from $ d_{i,1}d_{i,2}\\dots d_{i,m_i} $ using exactly $ k_i $ swaps of digits, such that no leading zero is introduced.  \n- $ \\max_i $: the lexicographically largest integer obtainable under the same constraints.  \n\nOutput $ \\min_i $ and $ \\max_i $ for each test case.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10211B","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}