CF BUDDY
← Problems·

1216E1 · Numerical Sequence (easy version)

1900 · binary search, brute force, math

Problem: The only difference between the easy and the hard versions is the maximum value of kk.

You are given an infinite sequence of form "112123123412345\dots" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 11 to 11, the second one — from 11 to 22, the third one — from 11 to 33, \dots, the ii-th block consists of all numbers from 11 to ii.

So the first 5656 elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the 11-st element of the sequence is 11, the 33-rd element of the sequence is 22, the 2020-th element of the sequence is 55, the 3838-th element is 22, the 5656-th element of the sequence is 00.

Your task is to answer qq independent queries. In the ii-th query you are given one integer kik_i. Calculate the digit at the position kik_i of the sequence.

Input Format: The first line of the input contains one integer qq (1q5001 \le q \le 500) — the number of queries.

The ii-th of the following qq lines contains one integer kik_i (1ki109)(1 \le k_i \le 10^9) — the description of the corresponding query.

Output Format: Print qq lines. In the ii-th line print one digit xix_i (0xi9)(0 \le x_i \le 9) — the answer to the query ii, i.e. xix_i should be equal to the element at the position kik_i of the sequence.

Note: Answers on queries from the first example are described in the problem statement.

Sample Cases

Case 1

Input

5
1
3
20
38
56

Output

1
2
5
2
0

Case 2

Input

4
2132
506
999999999
1000000000

Output

8
2
9
8

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback