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.util.*;
import java.io.*;
import java.math.*;
public class splset{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
			long n = sc.nextLong();
			StringBuilder sb = new StringBuilder();
			int flag1=1;
			for(int i=1;i<=1000000;i++){
				sb.append(flag1);
				flag1++;
			}
			ArrayList<Long> al = new ArrayList<>();
			ArrayList<Long> count = new ArrayList<>();
			long total=1;
			al.add(1l);
			long temp=0;
			long prev=0;
			long fg=1;
			long c=1;
			int flag=1;
			for(int i=1;;i++){
				
				prev+=(1);
				if(c>=1000000000)
					prev+=9;
				else if(c>=100000000)
					prev+=8;
				else if(c>=10000000)
					prev+=7;
				else if(c>=1000000)
					prev+=6;
				else if(c>=100000){
					prev+=5;
				}
				else if(c>=10000){
					prev+=4;
				}
				else if(c>=1000){
					prev+=3;
				}
				else if(c>=100){
					prev+=2;
				}
				else if(c>=10){
					prev+=1;
					
				}
				
				total+=prev;
				al.add(total);
				c++;
				flag++;
				if(total>1e9+7)
					break;
			}
			for(int i=0;i<n;i++){
				int val = sc.nextInt();
				for(int j=0;j<al.size();j++){
					if(al.get(j+1)>val){
						long diff = val-al.get(j);						
						System.out.println(sb.charAt((int)diff));
						break;
					}
				}
			}
	}
	
	
	public static long calc(long num , long a, long b, long c){
		long lcmas  = (a*b)/gcd(a,b);
		long lcmbs  = (c*b)/gcd(c,b);
		long lcmcs  = (a*c)/gcd(a,c);
		long lcmll  = (lcmas*c)/gcd(c,lcmas);
		
		return (num/a)+(num/b)+(num/c)- (num/lcmas) - (num/lcmbs) - (num/lcmcs) + (num/lcmll);
		
	}
	
	
	
	
	
	//static HashMap<Integer,Integer> visited = new HashMap<>();
		
	
	/*public static int compute(int root, int n, int m, Tree[] edge, int values[]){
			
			LinkedList<Integer> ll = 	new LinkedList<>();
			ll.add(root);
				
			while(ll.size()>0){
				int val = ll.removeFirst();
				visited.put(val,0);
				ArrayList<Integer> al = edge[val].al;
				int length = al.size();
				for(int i=0;i<length;i++){
					ll.addLast(al.get(i));
					int hold = edge[val].weight+values[root];
					values[al.get(i)] = Math.min(hold,values[al.get(i)]);
				}
			}
			return values[n];
			
	}*/
	
	
	public static class Tree{
		int weight;
		int destination;
	}
	
	
	
	public static int partition(int [] arr, int s, int e){
		
		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}
	
	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}
	
	
	public static long gcd(long a, long b){
		if(b==0)
			return a;
		
		return gcd(b,a%b);
	}
	
	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}
	
	public static class pair{
		int val;
		int index;
	}
	
	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o2.val-o1.val;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
}