Codeforces Round 1004 (Div. 2)
C
Devyatkino
Codeforces
1500
原题
← BD →
翻译中…

You are given a positive integer $n$. In one operation, you can add to $n$ any positive integer whose decimal representation contains only the digit $9$, possibly repeated several times.

翻译中…

What is the minimum number of operations needed to make the number $n$ contain at least one digit $7$ in its decimal representation?

翻译中…

For example, if $n = 80$, it is sufficient to perform one operation: you can add $99$ to $n$, after the operation $n = 179$, which contains the digit $7$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains an integer $n$ ($10 \leq n \leq 10^9$).

翻译中…

Output

翻译中…

For each test case, output the minimum number of operations required for the number $n$ to contain the digit $7$.

翻译中…

Note

翻译中…

In the first test case, three operations are sufficient: $51 + 9 + 9 + 9 = 78$, which contains the digit $7$. It can be shown that it is impossible to achieve the goal in one or two operations.

翻译中…

In the second test case, two operations are sufficient: $60 + 9 + 9 = 78$.

翻译中…

In the third test case, one operation is sufficient: $61 + 9 = 70$.

翻译中…

In the fourth test case, $n$ already contains the digit $7$, so no operations are required.

翻译中…

In the fifth test case, you can add $99$ to $n$ to obtain a number containing the digit $7$.

翻译中…

样例

Input #1
16
51
60
61
777
12345689
1000000000
2002
3001
977
989898986
80
800001
96
70
15
90
Output #1
3
2
1
0
1
3
5
4
0
7
1
2
7
0
7
3
InputCopy OutputCopy
题目信息
题号
2067C
时间限制
2 s
内存限制
256 MB
标签
暴力
DFS 及类似
贪心
数学

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