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.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, sc, out);
        out.close();
    }

    static class Task {
    	public static final long Max=(long) 1e9;
    	public static final int N=(int) 5e8;
    	public long[] dt = new long[17];
    	
    	long prefixlen(long h)
    	{
    		long ret = 0;
    		for(int d = 1;;d++){
    			if(h < dt[d-1])break;
    			if(h >= dt[d]){
    				long lret = 0;
    				long asc = dt[d] - dt[d-1];
    				lret += asc*(asc+1)/2;
    				lret += (h-dt[d]+1) * asc;
    				ret += lret * d;
    			}else{
    				long lret = 0;
    				long asc = h-dt[d-1]+1;
    				lret += asc*(asc+1)/2;
    				ret += lret * d;
    			}
    		}
    		return ret;
    	}
    	
    	
        public void solve(int testNumber, InputReader sc, PrintWriter out) throws IOException {
        	long[] s=new long[50];
            long ans=10;
            int index=0;
            s[1]=10;
            for(int i=2;i<=49;i++) {
                s[i]=9*ans*i+s[i-1];
                ans*=10;
                index=i;
                if(s[i]>Max)
                    break;
                 
            }
            dt[0] = 1;
    		for(int i = 1;i < 17;i++)
    			dt[i] = dt[i-1] * 10;
        	
        	int q=sc.nextInt();
        	while(q-->0) {
        		long k=sc.nextLong();
        		int l=1;
        		int r=N-1;
        		int now=0;
        		while(l<=r) {
        			int mid=(l+r)>>1;
        		    if(prefixlen(mid)>=k) {
        		    	now=mid;
        		    	r=mid-1;
        		    }
        		    else
        		    	l=mid+1;
        		}
        	     k-=prefixlen(now-1);
        	     k++;
        		 int end=0;
                 if(k-1>=1&&k-1<=9)
                     out.println(k-1);
                 else {
                     for(int i=1;i<=index;i++) {
      
                         if(k<=s[i]) {
                             end=i;
                             break;
                         }
                     }
                      
                     k-=s[end-1];
                      
                     int res=(int) (k%end);
                     long d=k/end;
                     if(res==0)
                         d--;
                     long begin=(long) (Math.pow(10, end-1))+d;
                      
                     String cnt=Long.toString(begin);
                     if(res==0)
                         res=end;
                     out.println(cnt.charAt(res-1));
                 }
        	}
        }

    }

    static class InputReader {
        private InputStreamReader reader;
        private char[] buf;
        private int len, now;
     
        public InputReader(InputStream stream) {
            reader = new InputStreamReader(stream);
            buf = new char[1024];
            len = 0;
            now = 0;
        }
     
        public String next() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            StringBuilder sb = new StringBuilder();
            while (!isSpaceChar(buf[now])) {
                sb.append(buf[now]);
                if (!move()) break;
            }
            return sb.toString();
        }
     
        public int nextInt() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            boolean x = false;
            if (buf[now] == '-') {
                x = true;
                if (!move()) throw new NumberFormatException();
            }
            int ans = 0;
            while (!isSpaceChar(buf[now])) {
                if (isNum(buf[now])) ans = ans * 10 + buf[now] - '0';
                else throw new NumberFormatException();
                if (!move()) break;
            }
            return (x ? -1 : 1) * ans;
        }
     
        public String nextLine() throws IOException {
            if (!hasNextLine()) throw new NullPointerException();
            StringBuilder sb = new StringBuilder();
            while (buf[now] != '\n') {
                sb.append(buf[now]);
                if (!move()) return sb.toString();
            }
            now++;
            return sb.toString();
        }
     
        public long nextLong() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            boolean x = false;
            if (buf[now] == '-') {
                x = true;
                if (!move()) throw new NumberFormatException();
            }
            long ans = 0;
            while (!isSpaceChar(buf[now])) {
                if (isNum(buf[now])) ans = ans * 10 + buf[now] - '0';
                else throw new NumberFormatException();
                if (!move()) break;
            }
            return (x ? -1 : 1) * ans;
        }
     
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
     
        public int nextHexInt() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            boolean x = false;
            if (buf[now] == '-') {
                x = true;
                if (!move()) throw new NumberFormatException();
            }
            int ans = 0;
            while (!isSpaceChar(buf[now])) {
                if (isHex(buf[now])) ans = ans * 16 + toHex(buf[now]);
                else throw new NumberFormatException();
                if (!move()) break;
            }
            return (x ? -1 : 1) * ans;
        }
     
        public char nextChar() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            char tmp = buf[now];
            move();
            return tmp;
        }
        public int next(char[] s) throws IOException {
            if (!hasNext()) throw new NullPointerException();
            int len=0;
            while (!isSpaceChar(buf[now])&&len<s.length) {
                s[len++]=buf[now];
                if (!move()) break;
            }
            return len;
        }
        public boolean hasNext() throws IOException {
            return skip();
        }
     
        public boolean hasNextLine() throws IOException {
            return now < len || refill();
        }
     
        private boolean move() throws IOException {
            now++;
            return hasNextLine();
        }
     
        private boolean skip() throws IOException {
            if (!hasNextLine()) return false;
            while (isSpaceChar(buf[now])) {
                if (!move()) return false;
            }
            return true;
        }
     
        private boolean isSpaceChar(char c) {
            return !(c >= 33 && c <= 126);
        }
     
        private boolean isNum(char c) {
            return c >= '0' && c <= '9';
        }
     
        private boolean isHex(char c) {
            return c >= '0' && c <= '9' || c >= 'A' && c <= 'F';
        }
     
        private int toHex(char c) {
            if (c >= '0' && c <= '9') return c - '0';
            else return c - 'A' + 10;
        }
     
        private boolean refill() throws IOException {
            len = reader.read(buf);
            now = 0;
            return len > 0;
        }
    }
}
