Codeforces Round 905 (Div. 3)
A
Morning
Codeforces
800
原题
←B →
翻译中…

You are given a four-digit pin code consisting of digits from $0$ to $9$ that needs to be entered. Initially, the cursor points to the digit $1$. 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.
翻译中…

image

翻译中…

The image above shows the device you are using to enter the pin code. For example, for the digit $5$, the adjacent digits are $4$ and $6$, and for the digit $0$, there is only one adjacent digit, $9$.

翻译中…

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 $t$ ($1 \leq t \leq 10^4$) - 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 $4$, consisting of digits from $0$ to $9$.

翻译中…

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 $4$ times.

翻译中…

In the second test case, it can be done in $9$ seconds as follows:

翻译中…
  • Press the cursor.
  • Move the cursor to the digit $2$.
  • Press the cursor.
  • Move the cursor to the digit $3$.
  • Press the cursor.
  • Move the cursor to the digit $4$.
  • Move the cursor to the digit $5$.
  • Move the cursor to the digit $6$.
  • Press the cursor.
翻译中…

样例

Input #1
10
1111
1236
1010
1920
9273
0000
7492
8543
0294
8361
Output #1
4
9
31
27
28
13
25
16
33
24
InputCopy OutputCopy
题目信息
题号
1883A
时间限制
2 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。