{"raw_statement":[{"iden":"statement","content":"Let's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \\cdot maxDigit(a_{n}).$$\n\nHere $m i n D i g i t (x)$ and $m a x D i g i t (x)$ are the minimal and maximal digits in the decimal representation of $x$ without leading zeroes. For examples refer to notes.\n\nYour task is calculate $a_K$ for given $a_1$ and $K$.\n\nThe first line contains one integer $t$ ($1 <= t <= 1000$) — the number of independent test cases.\n\nEach test case consists of a single line containing two integers $a_1$ and $K$ ($1 <= a_1 <= 10^(18)$, $1 <= K <= 10^(16)$) separated by a space.\n\nFor each test case print one integer $a_K$ on a separate line.\n\n$a_1 = 487$ \n\n $a_2 = a_1 + m i n D i g i t (a_1) dot.op m a x D i g i t (a_1) = 487 + min (4, 8, 7) dot.op max (4, 8, 7) = 487 + 4 dot.op 8 = 519$ \n\n $a_3 = a_2 + m i n D i g i t (a_2) dot.op m a x D i g i t (a_2) = 519 + min (5, 1, 9) dot.op max (5, 1, 9) = 519 + 1 dot.op 9 = 528$ \n\n $a_4 = a_3 + m i n D i g i t (a_3) dot.op m a x D i g i t (a_3) = 528 + min (5, 2, 8) dot.op max (5, 2, 8) = 528 + 2 dot.op 8 = 544$ \n\n $a_5 = a_4 + m i n D i g i t (a_4) dot.op m a x D i g i t (a_4) = 544 + min (5, 4, 4) dot.op max (5, 4, 4) = 544 + 4 dot.op 5 = 564$ \n\n $a_6 = a_5 + m i n D i g i t (a_5) dot.op m a x D i g i t (a_5) = 564 + min (5, 6, 4) dot.op max (5, 6, 4) = 564 + 4 dot.op 6 = 588$ \n\n $a_7 = a_6 + m i n D i g i t (a_6) dot.op m a x D i g i t (a_6) = 588 + min (5, 8, 8) dot.op max (5, 8, 8) = 588 + 5 dot.op 8 = 628$\n\n"},{"iden":"input","content":"The first line contains one integer $t$ ($1 <= t <= 1000$) — the number of independent test cases.Each test case consists of a single line containing two integers $a_1$ and $K$ ($1 <= a_1 <= 10^(18)$, $1 <= K <= 10^(16)$) separated by a space."},{"iden":"output","content":"For each test case print one integer $a_K$ on a separate line."},{"iden":"note","content":"$a_1 = 487$  $a_2 = a_1 + m i n D i g i t (a_1) dot.op m a x D i g i t (a_1) = 487 + min (4, 8, 7) dot.op max (4, 8, 7) = 487 + 4 dot.op 8 = 519$  $a_3 = a_2 + m i n D i g i t (a_2) dot.op m a x D i g i t (a_2) = 519 + min (5, 1, 9) dot.op max (5, 1, 9) = 519 + 1 dot.op 9 = 528$  $a_4 = a_3 + m i n D i g i t (a_3) dot.op m a x D i g i t (a_3) = 528 + min (5, 2, 8) dot.op max (5, 2, 8) = 528 + 2 dot.op 8 = 544$  $a_5 = a_4 + m i n D i g i t (a_4) dot.op m a x D i g i t (a_4) = 544 + min (5, 4, 4) dot.op max (5, 4, 4) = 544 + 4 dot.op 5 = 564$  $a_6 = a_5 + m i n D i g i t (a_5) dot.op m a x D i g i t (a_5) = 564 + min (5, 6, 4) dot.op max (5, 6, 4) = 564 + 4 dot.op 6 = 588$  $a_7 = a_6 + m i n D i g i t (a_6) dot.op m a x D i g i t (a_6) = 588 + min (5, 8, 8) dot.op max (5, 8, 8) = 588 + 5 dot.op 8 = 628$"}],"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\\} $, let $ a_1^{(k)} \\in \\mathbb{Z}^+ $ and $ K^{(k)} \\in \\mathbb{Z}^+ $ be given.  \nDefine the recurrence:  \n$$\na_{n+1}^{(k)} = a_n^{(k)} + \\minDigit(a_n^{(k)}) \\cdot \\maxDigit(a_n^{(k)})\n$$  \nwhere for $ x \\in \\mathbb{Z}^+ $,  \n- $ \\minDigit(x) $ is the smallest digit in the decimal representation of $ x $ (no leading zeros),  \n- $ \\maxDigit(x) $ is the largest digit in the decimal representation of $ x $.\n\n**Constraints**  \n1. $ 1 \\le t \\le 1000 $  \n2. For each test case:  \n   - $ 1 \\le a_1^{(k)} \\le 10^{18} $  \n   - $ 1 \\le K^{(k)} \\le 10^{16} $\n\n**Objective**  \nFor each test case $ k $, compute $ a_{K^{(k)}}^{(k)} $.","simple_statement":"Given a starting number $ a_1 $, compute $ a_K $ using the rule:  \n$ a_{n+1} = a_n + (\\text{min digit of } a_n) \\times (\\text{max digit of } a_n) $.  \n\nFor each test case, you’re given $ a_1 $ and $ K $. Output $ a_K $.","has_page_source":false}