欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1611A.Make Even
Make Even
Polycarp has an integer that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times:
- Reverse the prefix of length (in other words, leftmost digits) of . So, the leftmost digit is swapped with the -th digit from the left, the second digit from the left swapped with ()-th left, etc. For example, if and , then the new value of will be .
Note that for different operations, the values of can be different. The number can be equal to the length of the number — in this case, the whole number 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 to make it even or determine that this is impossible.
You need to answer independent test cases.
Input
The first line contains the number () — the number of test cases.
Each of the following lines contains one integer (). It is guaranteed that the given number doesn't contain the digit 0.
Output
Print 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.
Note
In the first test case, , which is already an even number. Polycarp doesn't need to do anything, so the answer is .
In the second test case, . Polycarp needs to do operations:
- Select and reverse the prefix . The number becomes . This number is odd.
- Select and reverse the prefix . The number becomes . This number is even.
It can be shown that is the minimum possible number of operations that Polycarp needs to do with his number to make it even.
In the third test case, . Polycarp can reverse the whole number (choose a prefix of length ). It will become and this is an even number.
In the fourth test case, . No matter how hard Polycarp tried, he would not be able to make an even number.
Samples
4
3876
387
4489
3
0
2
1
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |