SP1441 CLEVER - The Clever Typist
Description
Blue Mary is a typist of some secret department.Now she has to type in many passwords in an hour,each of which has a fixed length: 6.Of course,the less times she presses the keyboard,the happier she is.
Unfortunately,the keyboard to type in the password is extraordinary designed to keep secrets.The keyboard has 6 particular keys instead of 10 number keys.To explain the usages of these keys,let's define the 6 position on the screen 1,2,3,4,5,6 from left to right.The keys' usages are shown below:
- Swap0: swap the digit in the cursor position and the digit in position 1.The cursor doesn't move.If the cursor is now in position 1,the digits on the screen won't be changed.
- Swap1: swap the digit in the cursor position and the digit in position 6.The cursor doesn't move.If the cursor is now in position 6,the digits on the screen won't be changed.
- Up: increase the digit in the cursor position by 1.If the digit in the cursor position is 9,no change will happen.
- Down: decrease the digit in the cursor position by 1.If the digit in the cursor position is 0,no change will happen.
- Left: move the cursor one position left.If the cursor is in position 1,no change will happen.
- Right: move the cursor one position right.If the cursor is in position 6,no change will happen.
Input Format
The first line contains a single integer t(about 1000).t lines follow,each contains two 6-digit string,which show the digits on the screen at start and the password Mary is to type in,separated by a single space.
Output Format
t lines,each contains a single integer - the answer.