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.*;
public class puredig
{
  public static void main(String args[])
  {
  	Scanner in = new Scanner(System.in);
    int q = in.nextInt();
    long arr[] = new long [100001];
    
    arr[1]=1;
    long prev=1;
    long diff=1;

    for(int i=2;i<=100000;i++)
    {
    	if(i==10||i==100||i==1000||i==10000||i==100000)
    	diff++;
    	prev=prev+diff;
        arr[i]=arr[i-1]+prev;
    }
    
    for(int f =0;f<q;f++)
    {
      long a = in.nextInt();
      int mid = search(arr,a,1,100000);
      a= a-arr[mid-1];
      int ans= predict(a);
      System.out.println(ans);
    }
     	
     	
   	
  }
  public static int search(long arr[], long x , int left, int right)
  {
  	if(left>right)
  	return -1;
  	int mid = left+(right-left)/2;
  	if(arr[mid]>=x&&arr[mid-1]<x)
  	return mid;
  	if(arr[mid]>x)
  	return search(arr,x,left,mid);
  	else
  	return search(arr,x,mid+1,right);
  }	
  public static int predict(long a)
  {
  	long count=9;
  	for(long i=1;i<=10;i++)
  	{
  	 long cur = i*count;
  	 if(a<=cur)
  	 {
          	   
  	   	long pos = a/i;
        long rem = a%i;
        if(rem==0)
        {
        	rem = i;
            pos--;
        }        
        long palat = i-rem+1;
        long galat = (long)Math.pow(10,i-1)+pos;
        long ans=0;
        while(palat>0)
        {
        	ans=galat%10;
        	galat=galat/10;
        	palat--;
        }
        return (int)ans;

  	 }
  	 else
  	 {
  	 	a=a-cur;
  	 	count=count*10;
  	 }
  	 	
  	}
  	return -1;
  }
}