{"problem":{"name":"B. The Little Match Girl","description":{"content":"Using at most 7 matchsticks, you can draw any of the 10 digits as in the following picture:  Zaytoonah has a number that consists of N digits. She wants to move some sticks (zero or more) to maximize","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10110B"},"statements":[{"statement_type":"Markdown","content":"Using at most 7 matchsticks, you can draw any of the 10 digits as in the following picture: \n\nZaytoonah has a number that consists of N digits. She wants to move some sticks (zero or more) to maximize the number. Note that she doesn’t want to remove any of the sticks, she will only move them from one place to another within the N digits. She also doesn’t want to add new digits as N is her lucky number.\n\nCan you help Zaytoonah maximize her number?\n\nThe first line of input contains a single integer T, the number of test cases.\n\nEach test case contains a single integer N (1 ≤ N ≤ 105), followed by a space, then N digits that represent the number Zaytoonah currently has.\n\nFor each test case, print on a single line the maximum number Zaytoonah can get.\n\n## Input\n\nThe first line of input contains a single integer T, the number of test cases.Each test case contains a single integer N (1 ≤ N ≤ 105), followed by a space, then N digits that represent the number Zaytoonah currently has.\n\n## Output\n\nFor each test case, print on a single line the maximum number Zaytoonah can get.\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 number of digits ($ 1 \\leq n_k \\leq 10^5 $).  \n- Let $ D_k = (d_{k,1}, d_{k,2}, \\dots, d_{k,n_k}) $ be the sequence of digits representing the number, where each $ d_{k,i} \\in \\{0,1,\\dots,9\\} $.  \n\nLet $ c: \\{0,1,\\dots,9\\} \\to \\mathbb{Z}^+ $ be the function mapping each digit to the number of matchsticks required to display it, with:  \n$$\nc(0)=6,\\ c(1)=2,\\ c(2)=5,\\ c(3)=5,\\ c(4)=4,\\ c(5)=5,\\ c(6)=6,\\ c(7)=3,\\ c(8)=7,\\ c(9)=6\n$$\n\nLet $ R = \\sum_{i=1}^{n_k} c(d_{k,i}) $ be the total number of matchsticks used in the current number.\n\n**Constraints**  \n1. $ 1 \\leq T \\leq \\text{unspecified} $  \n2. $ 1 \\leq n_k \\leq 10^5 $  \n3. Each digit $ d_{k,i} \\in \\{0,1,\\dots,9\\} $  \n4. Total matchsticks $ R $ is fixed; no sticks added or removed, only rearranged.  \n5. Result must be a sequence of exactly $ n_k $ digits (no leading zeros unless $ n_k = 1 $).\n\n**Objective**  \nMaximize the lexicographical value of the digit sequence $ D_k' = (d_{k,1}', d_{k,2}', \\dots, d_{k,n_k}') $, subject to:  \n$$\n\\sum_{i=1}^{n_k} c(d_{k,i}') = R \\quad \\text{and} \\quad d_{k,i}' \\in \\{0,1,\\dots,9\\}\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10110B","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}