{"raw_statement":[{"iden":"problem statement","content":"You are given a length-$9$ sequence of non-negative integers $A=(A_1,A_2,\\dots,A_9)$. It is guaranteed that $2\\leq \\sum_{i=1}^{9}A_i$.\nYou can perform the following operation any number of times (possibly zero): choose one element of $A$ and add $1$ to it.\nWhat is the minimum number of operations required so that there exists a sequence of positive integers $S$ satisfying all of the following conditions?\n\n*   All elements of $S$ are between $1$ and $9$, inclusive.\n*   $S$ contains exactly $A_i$ occurrences of $i$ for each integer $i$ such that $1\\leq i\\leq 9$. (Thus, the length of $S$ is $\\sum_{i=1}^{9}A_i$.)\n*   No two adjacent elements sum to $10$.\n\nIt can be proved that the goal can be achieved in a finite number of operations.\nYou are given $T$ test cases; solve each of them."},{"iden":"constraints","content":"*   $1\\leq T\\leq 10^3$\n*   $0\\leq A_i\\leq 10^9$ $(1\\leq i\\leq 9)$\n*   $2\\leq \\sum_{i=1}^{9}A_i$\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$T$\n$\\text{case}_1$\n$\\text{case}_2$\n$\\vdots$\n$\\text{case}_T$\n\nEach test case is given in the following format:\n\n$A_1$ $A_2$ $\\dots$ $A_9$"},{"iden":"sample input 1","content":"2\n0 0 0 1 0 1 0 0 0\n2 1 1 0 0 0 0 0 0"},{"iden":"sample output 1","content":"1\n0\n\nFor the first test case, initially, the possible values of $S$ satisfying all conditions except the last one are $(4,6)$ and $(6,4)$, neither of which satisfies the last condition. By choosing $A_8$ and adding $1$ to it, $S=(6,8,4)$ satisfies all conditions.\nFor the second test case, $S=(1,2,3,1)$ satisfies the conditions without any operations."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}