Luggage Lock
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

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 to or in one step because the rotated digits are consecutive, but she can't rotate to 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.

输入描述:

The first line contains one integer T , 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.

输出描述:

For each test case, output a line containing a single integer, denoting the minimum steps needed to unlock.
示例1

输入

复制
6
1234 2345
1234 0123
1234 2267
1234 3401
1234 1344
1234 2468

输出

复制
1
1
4
5
1
4