Statement
You are given a decimal number of length .
You may delete some characters from . The relative order of the remaining characters does not change. At least one character must remain.
The number formed by the remaining characters must be divisible by or by . Find the minimum number of characters to delete. If this is impossible, print .
The resulting string may begin with . For example, represents the decimal number . The number is divisible by both and .
Input
The input is given in the following format:
Each case is given in the following format:
is the number of test cases. is a decimal number of length .
Output
For each test case, print the minimum number of characters to delete on one line. If it is impossible, print .
Constraints
- .
- .
- The first character of is not , and every character is a digit.
- The sum of over all test cases is at most .
Subtasks
Samples
In the first case, deleting the first produces . In the third case, no nonempty valid result exists.
In the fifth case, no deletion is needed. In the sixth case, deleting leaves .