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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
 * 
 * 	debug("Before submit:!!!!!!!!!!!!!!!!"); 
	debug(imie(MN), "MAKE SURE IT IS RIGHT!!!!!!!!!!!!!!!!!!!!!!!!  ");
	debug("LONG LONGS!!!!! ");
	debug("Check if m, n aren't misused  ");
	debug("Make sure output format is right (including YES/NO vs Yes/No vs Tak/Nie, newlines vs spaces)");
	debug("Run with n = 1");
	debug("Make sure two ints aren't multiplied to get a long long");
	debug("Read all compiler warnings");
	debug("Output enough digits after decimal point (%.20Lf)");
	debug("Hereby I confirm that I have done all above (Ctrl + D)");
 *
 */
public class Main {
	public static void main(String[] args) throws Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		Task task = new Task();
		task.solve(in, out);
		out.close();

	}

	static class Task {
		public void solve(InputReader in, PrintWriter out) {
			long[] numDitigs1toi = new long[44721 + 2];
			numDitigs1toi[1] = 1;
			for(int i = 2; i <= 44721; ++i) {
				if(i >= 1 && i <= 9) {
					numDitigs1toi[i] = 1 + numDitigs1toi[i - 1];
				} else if(i >= 10 && i <= 99) {
					numDitigs1toi[i] = 2 + numDitigs1toi[i - 1];
				} else if(i >= 100 && i <= 999) {
					numDitigs1toi[i] = 3 + numDitigs1toi[i - 1];
				} else if(i >= 1000 && i <= 9999) {
					numDitigs1toi[i] = 4 + numDitigs1toi[i - 1];
				} else if(i >= 10000 && i <= 99999) {
					numDitigs1toi[i] = 5 + numDitigs1toi[i - 1];
				}
			}
			
			long[] sumDigits1toi = new long[44721 + 2];
			
			sumDigits1toi[1] = numDitigs1toi[1];
			
			for(int i = 2; i <= 44721; ++i) {
				sumDigits1toi[i] = sumDigits1toi[i - 1] + numDitigs1toi[i];
			}
			
			//System.out.println(numDitigs1toi[44721] + " " + sumDigits1toi[44721]);
			int q = in.nextInt();
			
			for(int qq = 0; qq < q; ++qq) {
				long k = in.nextLong();
				//dado k quero encontrar o maior indice tal que a soma seja menor ou igual que k
				int low = 1;
				int high = 44721;
				
				int mid = (high + low) / 2;
				while(low <= high) {
					if(sumDigits1toi[mid] <= k) {
						low = mid + 1;
					} else {
						high = mid - 1;
					}
					mid = (high + low) / 2;
				}
				
				//sabendo isto, sei quantos digitos est�o a tr�s de k: sumDigits1toi[high]
				//
				//System.out.println(high + " " + numDitigs1toi[high]);
				
				low = 1;
				high = 44721;
				
				mid = (high + low) / 2;
				while(low <= high) {
					if(sumDigits1toi[mid] >= k) {
						
						high = mid - 1;
					} else {
						low = mid + 1;
					}
					mid = (high + low) / 2;
				}
				
				//System.out.println(low + " " + numDitigs1toi[low]);
				
				//int cnt = 0;
				StringBuffer bf = new StringBuffer();
				for(int i = 1; i <= low; ++i ) {
					bf.append(i);
				}
				//System.out.println(k - sumDigits1toi[high]);
				//System.out.println(bf.toString());
				out.println(bf.charAt((int) (k - sumDigits1toi[high] - 1)));
			}
			
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
               
            } catch (IOException e) {
            }
            return null;
        }


	}
}
