## Algorithm

E1. Numerical Sequence (easy version)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The only difference between the easy and the hard versions is the maximum value of k.

You are given an infinite sequence of form "112123123412345" 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, the i-th block consists of all numbers from 11 to i.

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 q independent queries. In the i-th query you are given one integer ki��. Calculate the digit at the position ki�� of the sequence.

Input

The first line of the input contains one integer q (1q5001≤�≤500) — the number of queries.

The i-th of the following q lines contains one integer ki�� (1ki109)(1≤��≤109) — the description of the corresponding query.

Output

Print q lines. In the i-th line print one digit xi�� (0xi9)(0≤��≤9) — the answer to the query i, i.e. xi�� should be equal to the element at the position ki�� of the sequence.

Examples
input
Copy
5
1
3
20
38
56

output
Copy
1
2
5
2
0

input
Copy
4
2132
506
999999999
1000000000

output
Copy
8
2
9
8

Note

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

## Code Examples

### #1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 1e6;
int q;
long long cm1[N];
long long cm2[N];

int get_digit(int n, int i) {
int nrev = 0;
while(n != 0) {
nrev *= 10;
nrev += (n % 10);
n /= 10;
}
int cnt = 0, cur = 0;
while(cnt != i) {
cur = nrev % 10;
nrev /= 10;
cnt += 1;
}

return cur;
}

int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
#endif

cm1[0] = cm2[0] = 0;
for(int i = 1; i < N; ++i)
cm1[i] = floor(log10(i)) + 1;
cm2[1] = 1;
for(int i = 2; i < N; ++i)
cm1[i] += cm1[i - 1], cm2[i] = cm1[i];
for(int i = 2; i < N; ++i)
cm2[i] += cm2[i - 1];

scanf("%d", &q);
for(int i = 0, tmp; i < q; ++i) {
scanf("%d", &tmp);
int idx = lower_bound(cm2 + 1, cm2 + N, tmp) - cm2;
tmp -= cm2[idx - 1];
idx = lower_bound(cm1 + 1, cm1 + N, tmp) - cm1;
printf("%d\n", get_digit(idx, tmp - cm1[idx - 1]));
}

return 0;
}
Copy The Code &

Input

cmd
5
1
3
20
38
56

Output

cmd
1
2
5
2
0