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^{18}) — 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
999999999999999999
1000000000000000000


Output


8
2
4
1

Note

Answers on queries from the first example are described in the problem statement.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	long oo = (long)3e18;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");
		
		long[] pow10 = new long[13];
		pow10[0] = 1;
		for(int i = 1; i < pow10.length; i++) {
			pow10[i] = 10*pow10[i-1];
		}
		
		long[] costAll10 = new long[13];
		costAll10[1] = 45;
		for(int i = 2; i < costAll10.length; i++) {
			long cnt = pow10[i];
			cnt -= pow10[i-1];
			costAll10[i] = mult(summation(cnt), i);
			for(int j = i-1; j > 0; j--) {
				long cntH = pow10[j];
				cntH -= pow10[j-1];
				costAll10[i] = add(costAll10[i], mult(mult(cntH, j), cnt));
			}
			costAll10[i] = add(costAll10[i], costAll10[i-1]);
		}
		
		int q = fs.nextInt();
		long MAX = (long)1e10;
		while(q-->0) {
			long K = fs.nextLong();
			long origK = K;
			long lo = 1, hi = MAX;
			long whichN = -1, cntBefore = 0;
			for(int bs = 0; bs < 50 && lo <= hi; bs++) {
				long mid = (lo+hi)/2;
				long costBefore = 0;
				long before = mid - 1;
				int len = (""+before).length();
				int myLen = (mid+"").length();
				if(mid > 1) {
					if(len == myLen) {
						costBefore = add(costBefore, costAll10[len-1]);
					}
					else {
						costBefore = add(costBefore, costAll10[len]);
					}
				}
				long beforeMe = 0;
				if(myLen == len) {
					//how many of equal len before me?
					int befPow = len-1;
					beforeMe = mid-pow10[befPow];
				}
				long add2 = 0;
				for(int otherLen = len == myLen ? len-1 : len; otherLen > 0; otherLen--) {
					long cnt = pow10[otherLen]-pow10[otherLen-1];
					add2 = add(add2, mult(cnt, otherLen));
				}
				
				long cnt1 = beforeMe;
				beforeMe = summation(beforeMe);
				beforeMe = mult(beforeMe, myLen);
				if(cnt1 > 0) beforeMe = add(beforeMe, mult(add2, cnt1));
				beforeMe = add(beforeMe, costBefore);
				
				if(K > beforeMe) {
					whichN = mid;
					cntBefore = beforeMe;
					lo = mid+1;
				}
				else {
					hi = mid-1;
				}
			}
			K -= cntBefore;
			
			//between [1,whichN] who am I?
			lo = 1; hi = whichN;
			long numPartOf = -1, cntOf = -1;
			for(int bs = 0; bs < 50 && lo <= hi; bs++) {
				long mid = (lo+hi)/2;
				int myLen = (""+mid).length();
				long beforeMe = 0;
				if(mid > 1) {
					int befLen = (""+(mid-1)).length();
					int stPow = -1;
					if(befLen == myLen) {
						stPow = befLen-1;
					}
					else stPow = befLen;
					for(int pow = stPow; pow > 0; pow--) {
						long cnt = pow10[pow]-pow10[pow-1];
						long len = pow;
						beforeMe = add(beforeMe, mult(cnt, len));
					}
					
					if(befLen == myLen) {
						int befPow = befLen-1;
						long belowMe = mid-pow10[befPow];
						beforeMe = add(beforeMe, mult(myLen, belowMe));
					}
				}
				if(K > beforeMe) {
					numPartOf = mid;
					cntOf = beforeMe;
					lo = mid+1;
				}
				else {
					hi = mid-1;
				}
			}
			
			K -= cntOf;
			String it = (""+numPartOf);
			out.println(it.charAt((int)(K-1)));
			
		}
		
		out.close();
	}
	
	long add(long a, long b) {
		if(a+b >= oo) return oo;
		return a+b;
	}
	
	long mult(long a, long b) {
		BigInteger tmp = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b));
		if(tmp.compareTo(BigInteger.valueOf(oo)) > 0) return oo;
		return tmp.longValue();
	}
	
	long summation(long N) {
		BigInteger tmp = BigInteger.valueOf(N).multiply(BigInteger.valueOf(N+1)).divide(BigInteger.valueOf(2));
		if(tmp.compareTo(BigInteger.valueOf(oo)) > 0) return oo;
		return tmp.longValue();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}