409051: GYM103427 J Luggage Lock
Description
Eileen has a big luggage and she would pick a lot of things in the luggage every time when A-SOUL goes out for a show. However, if there are too many things in the luggage, the 4-digit password lock on the luggage will be hard to rotate.
The state of lock is the four digits on the lock. In one step, she can choose consecutive digits to rotate up by one simultaneously or down by one simultaneously. For example, she can rotate $$$\texttt{0000}$$$ to $$$\texttt{0111}$$$ or $$$\texttt{0900}$$$ in one step because the rotated digits are consecutive, but she can't rotate $$$\texttt{0000}$$$ to $$$\texttt{0101}$$$ in one step. Since she has little strength, she wants to rotate the lock as few times as possible.
Now the lock is at state $$$a_0a_1a_2a_3$$$ and the password is $$$b_0b_1b_2b_3$$$. As a fan of A-SOUL, you are asked to help Eileen find out the optimal plan to unlock but you only need to tell Eileen how many times she has to rotate.
InputThe first line contains one integer $$$T$$$ $$$(1 \leq T \leq 10^5)$$$, denoting the numer of test cases.
Each of the test cases contains a line containing the initial state $$$a_0a_1a_2a_3$$$ and the target state $$$b_0b_1b_2b_3$$$.
OutputFor each test case, output a line containing a single integer, denoting the minimum steps needed to unlock.
ExampleInput6 1234 2345 1234 0123 1234 2267 1234 3401 1234 1344 1234 2468Output
1 1 4 5 1 4