Codeforces Round 756 (Div. 3) |
---|
Finished |
Polycarp has an integer $$$n$$$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times:
Note that for different operations, the values of $$$l$$$ can be different. The number $$$l$$$ can be equal to the length of the number $$$n$$$ — in this case, the whole number $$$n$$$ is reversed.
Polycarp loves even numbers. Therefore, he wants to make his number even. At the same time, Polycarp is very impatient. He wants to do as few operations as possible.
Help Polycarp. Determine the minimum number of operations he needs to perform with the number $$$n$$$ to make it even or determine that this is impossible.
You need to answer $$$t$$$ independent test cases.
The first line contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each of the following $$$t$$$ lines contains one integer $$$n$$$ ($$$1 \le n < 10^9$$$). It is guaranteed that the given number doesn't contain the digit 0.
Print $$$t$$$ lines. On each line print one integer — the answer to the corresponding test case. If it is impossible to make an even number, print -1.
4 3876 387 4489 3
0 2 1 -1
In the first test case, $$$n=3876$$$, which is already an even number. Polycarp doesn't need to do anything, so the answer is $$$0$$$.
In the second test case, $$$n=387$$$. Polycarp needs to do $$$2$$$ operations:
It can be shown that $$$2$$$ is the minimum possible number of operations that Polycarp needs to do with his number to make it even.
In the third test case, $$$n=4489$$$. Polycarp can reverse the whole number (choose a prefix of length $$$l=4$$$). It will become $$$9844$$$ and this is an even number.
In the fourth test case, $$$n=3$$$. No matter how hard Polycarp tried, he would not be able to make an even number.
Name |
---|