#arc174d. D - Digit vs Square Root

D - Digit vs Square Root

Score: 500500 points

问题陈述

解决以下问题,共 TT 个测试用例。

给定一个整数 NN,找出满足以下所有条件的整数 xx 的数量:

  • 1xN1 \le x \le N
  • y=xy = \lfloor \sqrt{x} \rfloor。当 xxyy 用十进制表示(没有前导零)时,yyxx 的前缀。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

Solve the following problem for TT test cases.

Given an integer NN, find the number of integers xx that satisfy all of the following conditions:

  • 1xN1 \le x \le N
  • Let y=xy = \lfloor \sqrt{x} \rfloor. When xx and yy are written in decimal notation (without leading zeros), yy is a prefix of xx.

Constraints

  • TT is an integer such that 1T1051 \le T \le 10^5.
  • NN is an integer such that 1N10181 \le N \le 10^{18}.

Input

The input is given from Standard Input in the following format:

TT

N1N_1

N2N_2

\vdots

NTN_T

Here, NiN_i represents the integer NN for the ii-th test case.

Output

Print TT lines in total. The ii-th line should contain the answer for the ii-th test case as an integer.

Sample Input 1

2
1
174

Sample Output 1

1
22

This input contains two test cases.

  • For the first test case, x=1x=1 satisfies the conditions since y=1=1y = \lfloor \sqrt{1} \rfloor = 1.
  • For the second test case, for example, x=100x=100 satisfies the conditions since y=100=10y = \lfloor \sqrt{100} \rfloor = 10.