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 java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E2NumericalSequenceHardVersion solver = new E2NumericalSequenceHardVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class E2NumericalSequenceHardVersion {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int q = in.scanInt();
            int hh = -1;
            long[] upto_i = new long[10000001];
            long[] upto_i1 = new long[10000001];
            for (int i = 1; i <= 10000000; i++) {
                int digit = 0;
                int temp = i;
                while (temp > 0) {
                    digit++;
                    temp /= 10;
                }
                upto_i1[i] += upto_i1[i - 1] + digit;
                upto_i[i] = upto_i[i - 1] + upto_i1[i - 1] + digit;
                if (upto_i[i] > 1e9) {
                    hh = i;
                    break;
                }
            }
            while (q-- > 0) {
                long k = in.scanLong();
                int low = 1;
                int high = hh;
                int index = -1;
                while (low <= high) {
                    int mid = (low + high) >> 1;
                    if (upto_i[mid] >= k) {
                        index = mid;
                        high = mid - 1;
                    } else {
                        low = mid + 1;
                    }
                }
                k -= upto_i[index - 1];
                int low1 = 1;
                int high1 = index;
                int index1 = -1;
                while (low1 <= high1) {
                    int mid1 = (low1 + high1) >> 1;
                    if (upto_i1[mid1] >= k) {
                        index1 = mid1;
                        high1 = mid1 - 1;
                    } else {
                        low1 = mid1 + 1;
                    }
                }
                k -= upto_i1[index1 - 1];

                out.println(String.valueOf(index1).charAt((int) k - 1));
            }


        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

    }
}

