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.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        new Main().run();}

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init1(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }


    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int[] unique(int a[]){
        int p = 1;
        for(int i=1;i<a.length;++i){
            if(a[i]!=a[i-1]){
                a[p++] = a[i];
            }
        }
        return Arrays.copyOf(a,p);
    }
    public static int eq_bigger(int[] a, int key) {
        return eq_bigger(a,0,a.length,key);
    }

    public static int eq_bigger(int[] a, int lo, int hi,
                                int key) {
        while (lo < hi) {
            int mid = (lo + hi) >>> 1;
            if (a[mid] < key) {
                lo = mid + 1;
            }else {
                hi = mid;
            }
        }
        return lo;
    }

    public static int bigger(int[] a, int key) {
        return bigger(a,0,a.length,key);
    }

    public static int bigger(int[] a, int lo, int hi,
                             int key) {
        while (lo < hi) {
            int mid = (lo + hi) >>> 1;
            if (a[mid] > key) {
                hi = mid;
            }else {
                lo = mid+1;
            }
        }
        return lo;
    }


    static int h[];
    static int to[];
    static int ne[];
    static int m = 0;

    public static void addEdge(int u, int v, int w) {
        to[++m] = v; ne[m] = h[u]; h[u] = m;
    }



    long w[];

    int cc = 0;

    void add(int u,int v,long ww) {
        to[++cc] = u;
        w[cc] = ww;
        ne[cc] = h[v];
        h[v] = cc;

        to[++cc] = v;
        w[cc] = ww;
        ne[cc] = h[u];
        h[u] = cc;
    }

    boolean isin(long z1[],long z2[]){
        return z2[0]<=z1[0]&&z2[1]<=z1[1]&&z2[2]>=z1[2]&&z2[3]>=z1[3];
    }

    boolean pisin(long p[],long z2[]){
        return z2[0]<=p[0]&&z2[1]<=p[1]&&z2[2]>=p[0]&&z2[3]>=p[1];
    }

    public static int lengthSum(int length){
        int count = 9;
        for(int i=1;i<length;i++)
            count*=10;
        return count*length;
    }
    public static int digitAtIndex(int index){
        if(index<0)
            return -1;
        if(index<10)
            return index;
        int curIndex = 10,length = 2;
        int boundNum = 10;
        while (curIndex+lengthSum(length)<index){
            curIndex+=lengthSum(length);
            boundNum*=10;
            length++;
        }
        int addNum = (index-curIndex)/length;
        int curNum = boundNum + addNum;
        return Integer.toString(curNum).charAt(index-curIndex-addNum*length)-'0';
    }


    void solve() {
        long dp[] = new long[1000000];
        dp[1] = 1;
        for(int i=2;i<1000000;++i){
            int w = (""+i).length();
            dp[i] = dp[i-1]+w;
        }

        int q = ni();
        for(int i=0;i<q;++i){
            long k = nl();
            long sum = 0;
            int ii=1;
            for(;ii<1000000;++ii){
                if(sum+dp[ii]<=k){
                    sum+= dp[ii];
                }else{
                    break;
                }
            }
            if(k==sum){
                ii--;
                String u = ""+ii;
                println(u.charAt(u.length()-1));
            }else{
                k -= sum;
                println(digitAtIndex((int)k));


            }

        }










    }




















































    static class S{
        int l = 0;
        int r = 0 ;
        int idx = 0;
        long all = 0;

        public S(int l,int r) {
            this.l = l;
            this.r = r;
        }
    }

    static S a[];
    static int[] o;

    static void init(int[] f){
        o = f;
        int len = o.length;
        a = new S[len*4];
        build(1,0,len-1);
    }

    static void build(int num,int l,int r){
        S cur = new S(l,r);
        if(l==r){
            a[num] = cur;
            a[num].all = o[l];
            a[num].idx = l;
            return;
        }else{
            int m = (l+r)>>1;
            int le = num<<1;
            int ri = le|1;
            build(le, l,m);
            build(ri, m+1,r);
            a[num] = cur;
            pushup(num, le, ri);
        }
    }



    static int[] query(int num,int l,int r){

        if(a[num].l>=l&&a[num].r<=r){
            return new int[]{a[num].idx,(int)a[num].all};
        }else{
            int m = (a[num].l+a[num].r)>>1;
            int le = num<<1;
            int ri = le|1;
            //   pushdown(num, le, ri);
            int ma = -1;
            int idx = 100000001;
            if(l<=m) {
                int r1[] = query(le, l, r);
                if(r1[1]>ma){
                    ma = r1[1];
                    idx = r1[0];
                }

            }
            if(r>m){
                int r2[] = query(ri, l, r);
                if(r2[1]>ma){
                    ma = r2[1];
                    idx = r2[0];
                }
            }
            return new int[]{idx,ma};
        }
    }


    static void update(int num,int l,long v){
        if(a[num].l==a[num].r){
            a[num].all = v;
        }else{
            int m = (a[num].l+a[num].r)>>1;
            int le = num<<1;
            int ri = le|1;
            pushdown(num, le, ri);
            if(l<=m){
                update(le,l,v);
            }
            if(l>m){
                update(ri,l,v);
            }
            pushup(num,le,ri);
        }
    }

    static void pushup(int num,int le,int ri){
        a[num].all = Math.max(a[le].all,a[ri].all);
        if(a[le].all>a[ri].all){
            a[num].idx = a[le].idx;
        }else{
            a[num].idx = a[ri].idx;
        }

    }
    static void pushdown(int num,int le,int ri){

    }


    long gcd(long a,long b){ return b==0?a: gcd(b,a%b);}
    InputStream is;PrintWriter out;
    void run() throws Exception {is = System.in;out = new PrintWriter(System.out);solve();out.flush();}
    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;
    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {lenbuf = is.read(inbuf);} catch (IOException e) {throw new InputMismatchException();}
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];}
    private boolean isSpaceChar(int c) {return !(c >= 33 && c <= 126);}
    private int skip() {int b;while((b = readByte()) != -1 && isSpaceChar(b));return b;}
    private double nd() {return Double.parseDouble(ns());}
    private char nc() {return (char) skip();}
    private char ncc() {int b;while((b = readByte()) != -1 && !(b >= 32 && b <= 126));return (char)b;}
    private String ns() {int b = skip();StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);b = readByte(); }
        return sb.toString();}
    private char[] ns(int n) {char[] buf = new char[n];int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b;b = readByte(); }
        return n == p ? buf : Arrays.copyOf(buf, p);}
    private String nline() {int b = skip();StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') { sb.appendCodePoint(b);b = readByte(); }
        return sb.toString();}
    private char[][] nm(int n, int m) {char[][] a = new char[n][];for (int i = 0; i < n; i++) a[i] = ns(m);return a;}
    private int[] na(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = ni();return a;}
    private long[] nal(int n) { long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nl();return a;}
    private int ni() { int num = 0, b; boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
        if (b == '-') { minus = true; b = readByte(); }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();}}
    private long nl() { long num = 0; int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
        if (b == '-') { minus = true; b = readByte(); }
        while (true) {
            if (b >= '0' && b <= '9')  num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();}}
    void print(Object obj){out.print(obj);}
    void println(Object obj){out.println(obj);}
    void println(){out.println();}
}