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 .
The input is given in the following format:
For each test case, print the minimum number of characters to delete on one line. If it is impossible, print .
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 .
Each case is given in the following format:
is the number of test cases. is a decimal number of length .
| 3 | 54 | No additional constraints. |