PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000191. Dãy chữ số (phiên bản dễ) (Numerical Sequence (Easy Version))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy chữ số (phiên bản dễ) (Numerical Sequence (Easy Version))

Numerical Sequence (Easy Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Consider an infinite string of decimal digits formed by concatenating blocks. Block ii is constructed by writing the positive integers 1,2,…,i1,2,\ldots,i consecutively, without separators.

The first blocks are 1, 12, 123, 1234, ...; their concatenation begins with 1121231234....

Digits in the infinite string are indexed starting from 11. For each independent query, find the single digit at position kik_i. Queries do not modify the string.

Input

  • The first line contains qq, the number of queries.
  • Each of the following qq lines contains an integer kik_i, the queried digit position.

Output

  • Print qq lines. Line ii contains one digit from 0 to 9, at position kik_i.

Subtasks

  • Subtask 1 (20 points): 1≤q≤101\le q\le 10; 1≤ki≤100001\le k_i\le 10000 for every 1≤i≤q1\le i\le q.
  • Subtask 2 (30 points): 1≤q≤1001\le q\le 100; 1≤ki≤10000001\le k_i\le 1000000 for every 1≤i≤q1\le i\le q.
  • Subtask 3 (50 points): 1≤q≤5001\le q\le 500; 1≤ki≤10000000001\le k_i\le 1000000000 for every 1≤i≤q1\le i\le q.

Examples

Input

5
1
3
20
38
56

Output

1
2
5
2
0

Explanation

The five queries ask for positions 1,3,20,38,561,3,20,38,56. The prefix of the infinite sequence is 11212312341234512345612345671234567812345678912345678910.

Counting digits from 1: position 11 is 1; position 33 is 2; position 2020 is 5; position 3838 is 2; and position 5656 is the last digit of 10, namely 0. These are precisely the five output lines.