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.
/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class NumericalSequence {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        //11212312341234512345612345671234567812345678912345678910
        //11212312341234512345612345671234567812345678912345678910
        int Q = sc.nextInt();
//        int i = 1;
        while (Q-->0) {
            long K = sc.nextLong();
            long N = binarySearchNumber(K);
            long delta = K - digits(N);
            if (delta == 0) {
                String s = N + "";
                out.println(s.charAt(s.length() - 1));
            }
            else {
                long num = binarySearchSmall(delta, N);
                long delta2 = delta - seqLength(num);
                // we are right before the number, just how far inside
                // the length of the number is needed!
                char dig;
                if (delta2 > 0) {
                    num++; // overflow into next number
                    String s = (num) + "";
                    dig = s.charAt((int) delta2 - 1);
                }
                else {
                    String s = (num) + "";
                    dig = s.charAt(s.length() - 1 - (int) delta2);
                }

                out.println(dig);
            }
        }
        out.close();
    }

    static long digits(long n) {
        long ans = n * (n + 1) / 2;
        long power = 10;
        while (power <= n) {
            ans += (n - power + 1) * (n - power + 2) / 2;
            power *= 10;
        }
        return ans;
    }

    // Find latest N, such that the digits function is less
    // than pos
    // 1111110000 -> 10
    static long binarySearchNumber(long pos) {
        long lo = 1;
        long hi = pos;
        while (lo < hi) {
            long mid = (hi - lo) / 2 + lo + 1;
            if (digits(mid) <= pos) {
                lo = mid;
            }
            else {
                hi = mid - 1; // creep downward
            }
        }
        return lo;
    }

    static long seqLength(long n) {
        long ans = n;
        long power = 10;
        while (power <= n) {
            ans += (n - power + 1);
            power *= 10;
        }
        return ans;
    }

    // A certain delta above "last"
    // We have an upper bound of last + 1, but we climb up
    // until the number of digits works to equal delta!
    // Find the last number, such that counting all digits up
    // to and including is <= delta
    // 1111000
    static long binarySearchSmall(long delta, long last) {
        long lo = 1;
        long hi = last + 1;
        while (lo < hi) {
            long mid = (hi - lo) / 2 + lo + 1;
            if (seqLength(mid) <= delta) {
                lo = mid;
            }
            else {
                hi = mid - 1; // doesn't matter, since only 1 will work
            }
        }
        return lo;
    }

    static class FastScanner {
        public int BS = 1<<16;
        public char NC = (char)0;
        byte[] buf = new byte[BS];
        int bId = 0, size = 0;
        char c = NC;
        double cnt = 1;
        BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            }
            catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar(){
            while(bId==size) {
                try {
                    size = in.read(buf);
                }catch(Exception e) {
                    return NC;
                }
                if(size==-1)return NC;
                bId=0;
            }
            return (char)buf[bId++];
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public long nextLong() {
            cnt=1;
            boolean neg = false;
            if(c==NC)c=getChar();
            for(;(c<'0' || c>'9'); c = getChar()) {
                if(c=='-')neg=true;
            }
            long res = 0;
            for(; c>='0' && c <='9'; c=getChar()) {
                res = (res<<3)+(res<<1)+c-'0';
                cnt*=10;
            }
            return neg?-res:res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c!='.' ? cur:cur+nextLong()/cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c>32) {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c!='\n') {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if(c>32)return true;
            while(true) {
                c=getChar();
                if(c==NC)return false;
                else if(c>32)return true;
            }
        }
    }
}