#P7826. Fragrant numbers
Fragrant numbers
Fragrant numbers
Problem Description
Many people love numbers, and some have a penchant for specific numbers. Nowadays in popular culture, 1145141919 is a very fragrant number, and many people want to represent all other numbers with this number. Let be an infinite string of "1145141919" infinitely stitched together as "114514191911451419191145141919...". Take a prefix of , you can insert '' , '' , '' or '' to to form a new string , and then let the value of be according to ordinary rules. (You can insert any number of operators, even 0. But need to ensure that the inserted operators form legitimate operations) Now for a number , please calculate the minimum length of that can make . For example, when , the minimum length of (pick the first characters and insert operators to make , then we have ) If no such exists, output .
Input
There are multiple test cases. The first line with a number indicates the number of test cases. For each test case, one integer per line indicates an inquiry.
Output
Output lines. One integer per line indicates the corresponding answer.
Sample Input
3
520
1
2
Sample Output
6
1
2
Source
2020 Multi-University Training Contest 6