#CF2230B. B. Digit String
B. Digit String
B. Digit String
You are given a string consisting of digits from to .
Let's say that the string is beautiful if it is impossible to select some of its elements and write them out (in the same order as they appear in the string) to form a number that is a multiple of . For example, the strings 31, 222, 213 are beautiful, while the strings 143, 3123, 1322 are not. The empty string is considered beautiful.
Your task is to calculate the minimum possible number of elements in the string that need to be removed in order to make it beautiful.
The first line contains a single integer () — the number of test cases.
The only line of each test case contains a string (), consisting of digits from to .
Additional constraint on the input: the sum of the lengths of over all test cases doesn't exceed .
For each test case, print a single integer — the minimum possible number of elements in the string that need to be removed in order to make it beautiful.
ExampleNoteIn the first example, you have to delete the whole string.
In the second example, the string is already beautiful.
In the third example, you can delete the -st, -rd, -th, and -th characters, and you will get the string 213.
Input
InputThe first line contains a single integer () — the number of test cases.
The only line of each test case contains a string (), consisting of digits from to .
Additional constraint on the input: the sum of the lengths of over all test cases doesn't exceed .
Output
OutputFor each test case, print a single integer — the minimum possible number of elements in the string that need to be removed in order to make it beautiful.
Samples
5
4
13
1322
222
31
1
0
2
0
0
Note
NoteIn the first example, you have to delete the whole string.
In the second example, the string is already beautiful.
In the third example, you can delete the -st, -rd, -th, and -th characters, and you will get the string 213.