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 1 to 1, the second one — from 1 to 2, the third one — from 1 to 3, ..., the i-th block consists of all numbers from 1 to i. 

So the first 56 elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the 1-st element of the sequence is 1, the 3-rd element of the sequence is 2, the 20-th element of the sequence is 5, the 38-th element is 2, the 56-th element of the sequence is 0.

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

Input

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

The i-th of the following q lines contains one integer k_i (1 ≤ k_i ≤ 10^9) — the description of the corresponding query.

Output

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

Examples

Input


5
1
3
20
38
56


Output


1
2
5
2
0


Input


4
2132
506
999999999
1000000000


Output


8
2
9
8

Note

Answers on queries from the first example are described in the problem statement.
import io
import os
import collections
import math
import functools
import itertools
import bisect
import heapq
from sys import stdin, stdout, stderr
from collections import *
from math import *
from functools import *
from itertools import *
from heapq import *
from bisect import bisect_left, bisect_right, insort_left, insort_right

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_ints(): return list(map(int, input().split()))
def get_int(): return int(input())
def get_str(): return "".join(list(map(chr, input()))[:-1])
def eprint(*args): stderr.write(", ".join(map(str, args)) + "\n")
def print(*args): stdout.write(" ".join(map(str, args)) + "\n")


# **************************************************************************** #
q = get_int()
arr = [get_int() for _ in range(q)]
arr = [(x, i) for i, x in enumerate(arr)]
arr.sort()
res = [0] * q

strs = []
s_ps = [0]
t_ps = [0]
s_len = 0
t_len = 0
x = 0
'''
1
112
1 12 123 1234 12345 123456 1234567 12345678 123456789 12345678910
11212312341234512345612345671234567812345678912345678910

'''
for n, i in arr:
    while t_len < n:
        x += 1
        xs = str(x)
        strs.append(xs)
        s_len += len(xs)
        s_ps.append(s_len)
        t_len += s_len
        t_ps.append(t_len)

    nn = n - t_ps[-2]
    si = bisect_left(s_ps, nn) - 1
    ss = strs[si] if si < len(strs) else None
    sci = nn - s_ps[si] - 1
    sc = ss[sci]
    #eprint(n, nn, i, strs, s_ps, t_ps, x, si, ss, sci, sc)

    res[i] = sc

for r in res:
    print(r)
