#d2847. 素数之欢
素数之欢
Prime Delight
Problem Description
You are given two four-digit prime numbers and . You may perform the following operation multiple times:
Change one digit of so that it becomes another four-digit prime number.
For example, , where both and are prime.
What is the minimum number of transformations needed to turn into ? Or answer that it is impossible.
Input Format
The first line contains an integer , indicating that groups of data follow.
The next lines each contain two four-digit primes separated by a space.
Output Format
Output lines. If possible, output the minimum number of transformations; otherwise output .
Sample Input
2
1033 1033
1033 8779
Sample Output
0
5
Sample Explanation
$$1033 \rightarrow 1\mathbf{7}33 \rightarrow \mathbf{3}733 \rightarrow 373\mathbf{9} \rightarrow 37\mathbf{7}9 \rightarrow \mathbf{8}779$$Hint
If possible at all, you will need at most operations.
Constraints
- Multiple test cases,