欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1883A.Morning
Morning
You are given a four-digit pin code consisting of digits from to that needs to be entered. Initially, the cursor points to the digit . In one second, you can perform exactly one of the following two actions:
- Press the cursor to display the current digit,
- Move the cursor to any adjacent digit.

The image above shows the device you are using to enter the pin code. For example, for the digit , the adjacent digits are and , and for the digit , there is only one adjacent digit, .
Determine the minimum number of seconds required to enter the given four-digit pin code.
Input
Each test consists of multiple test cases. The first line contains a single integer () - the number of the test cases. This is followed by their description.
The single line of each test case describes the pin code as a string of length , consisting of digits from to .
Output
For each test case, output the minimum number of seconds required to enter the given pin code.
Note
In the first test case, the cursor needs to be pressed times.
In the second test case, it can be done in seconds as follows:
- Press the cursor.
- Move the cursor to the digit .
- Press the cursor.
- Move the cursor to the digit .
- Press the cursor.
- Move the cursor to the digit .
- Move the cursor to the digit .
- Move the cursor to the digit .
- Press the cursor.
Samples
10
1111
1236
1010
1920
9273
0000
7492
8543
0294
8361
4
9
31
27
28
13
25
16
33
24
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |