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.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.Comparator.*;

public class Main {
    FastScanner in;
    PrintWriter out;
    ArrayList<Integer>[] graph;
    ArrayList<GraphPair>[] weightedGraph;
    long mod = (long) 1e9 + 7; // 998_244_353L || (long) 1e9 + 9
    boolean multitests = true;

    private void solve() throws IOException {
        // solveA();
        // solveB();
        // solveC();
        // solveD();
        solveE();
        // solveF();
        // solveG();
        // solveH();
        // solveI();
        // solveJ();
        // solveK();
        // solveL();
    }

    private void solveA() throws IOException {
        int n = in.nextInt(), ans = 0;
        char[] s = in.next().toCharArray();
        for (int i = 0; i + 1 < n; i += 2) {
            if (s[i] == s[i + 1]) {
                s[i] = 'a';
                s[i + 1] = 'b';
                ans++;
            }
        }
        out.println(ans);
        out.println(new String(s));
    }

    private void solveB() throws IOException {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        Integer[] id = new Integer[n];
        for (int i = 0; i < n; i++)
            id[i] = i;
        sort(id, comparingInt(o -> -a[o]));
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += a[id[i]] * i + 1;
        }
        out.println(ans);
        for (int i = 0; i < n; i++) {
            out.print(id[i] + 1 + " ");
        }
    }

    private void solveC() throws IOException {
        long[] w = in.nextLongArray(4);
        long[] b1 = in.nextLongArray(4);
        long[] b2 = in.nextLongArray(4);
        if ((w[2] - w[0]) * (w[3] - w[1]) -
                max(0, min(w[2], b1[2]) - max(w[0], b1[0])) * max(0, min(w[3], b1[3]) - max(w[1], b1[1])) -
                max(0, min(w[2], b2[2]) - max(w[0], b2[0])) * max(0, min(w[3], b2[3]) - max(w[1], b2[1])) +
                max(0, min(min(w[2], b1[2]), b2[2]) - max(max(w[0], b1[0]), b2[0])) *
                        max(0, min(min(w[3], b1[3]), b2[3]) - max(max(w[1], b1[1]), b2[1])) > 0) {
            out.println("YES");
        } else {
            out.println("NO");
        }
    }

    private void solveD() throws IOException {
        int n = in.nextInt();
        long[] a = in.nextLongArray(n);
        shuffleLong(a);
        sort(a);
        long gcd = 0;
        for (int i = 0; i + 1 < n; i++) {
            gcd = gcd(gcd, a[i + 1] - a[i]);
        }
        long ans = 0;
        for (int i = 0; i < n; i++)
            ans += (a[n - 1] - a[i]) / gcd;
        out.println(ans + " " + gcd);
    }

    private void solveE() throws IOException {
        long x = in.nextLong();
        long digitsCnt = 1, prevLen = 0, curLen = 9, curNine = 9, sum = 45;
        while (sum < x) {
            digitsCnt++;
            prevLen = curLen;
            curNine = 9;
            for (int i = 0; i < digitsCnt - 1; i++)
                curNine *= 10;
            curLen = prevLen + curNine * digitsCnt;
            sum += (prevLen + digitsCnt + curLen) * curNine / 2;
        }
        sum -= (prevLen + digitsCnt + curLen) * curNine / 2;
        curNine = 1;
        for (int i = 0; i < digitsCnt; i++)
            curNine *= 10;
        long l = curNine / 10 - 1, r = curNine - 1;
        while (l + 1 < r) {
            long m = (l + r) / 2;
            if (sum + (prevLen + digitsCnt + prevLen + (m - (curNine / 10 - 1)) * digitsCnt) * (m - (curNine / 10 - 1)) / 2 < x)
                l = m;
            else
                r = m;
        }
        sum += (prevLen + digitsCnt + prevLen + (l - (curNine / 10 - 1)) * digitsCnt) * (l - (curNine / 10 - 1)) / 2;
        x -= sum;

        digitsCnt = 1;
        curLen = 9;
        while (x > curLen * digitsCnt) {
            x -= curLen * digitsCnt;
            curLen *= 10;
            digitsCnt++;
        }
        x--;
        out.println(Long.toString(curLen / 9 + x / digitsCnt).charAt((int) (x % digitsCnt)));
    }

    private void solveF() throws IOException {

    }

    private void solveG() throws IOException {

    }

    private void solveH() throws IOException {

    }

    private void solveI() throws IOException {

    }

    private void solveJ() throws IOException {

    }

    private void solveK() throws IOException {

    }

    private void solveL() throws IOException {

    }

    void shuffleInt(int[] a) {
        Random random = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int j = random.nextInt(i + 1);
            int swap = a[j];
            a[j] = a[i];
            a[i] = swap;
        }
    }

    void shuffleLong(long[] a) {
        Random random = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int j = random.nextInt(i + 1);
            long swap = a[j];
            a[j] = a[i];
            a[i] = swap;
        }
    }

    void reverseInt(int[] a) {
        for (int i = 0, j = a.length - 1; i < j; i++, j--) {
            int swap = a[i];
            a[i] = a[j];
            a[j] = swap;
        }
    }

    void reverseLong(long[] a) {
        for (int i = 0, j = a.length - 1; i < j; i++, j--) {
            long swap = a[i];
            a[i] = a[j];
            a[j] = swap;
        }
    }

    int maxInt(int[] a) {
        int max = a[0];
        for (int i = 1; i < a.length; i++)
            if (max < a[i])
                max = a[i];
        return max;
    }

    long maxLong(long[] a) {
        long max = a[0];
        for (int i = 1; i < a.length; i++)
            if (max < a[i])
                max = a[i];
        return max;
    }

    int minInt(int[] a) {
        int min = a[0];
        for (int i = 1; i < a.length; i++)
            if (min > a[i])
                min = a[i];
        return min;
    }

    long minLong(long[] a) {
        long min = a[0];
        for (int i = 1; i < a.length; i++)
            if (min > a[i])
                min = a[i];
        return min;
    }

    long sumInt(int[] a) {
        long s = 0;
        for (int i = 0; i < a.length; i++)
            s += a[i];
        return s;
    }

    long sumLong(long[] a) {
        long s = 0;
        for (int i = 0; i < a.length; i++)
            s += a[i];
        return s;
    }

    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long binpowmod(long a, long n) {
        long res = 1;
        a %= mod;
        n %= mod - 1;
        while (n > 0) {
            if (n % 2 == 1)
                res = (res * a) % mod;
            a = (a * a) % mod;
            n /= 2;
        }
        return res;
    }

    class GraphPair implements Comparable<GraphPair> {
        int v;
        long w;

        GraphPair(int v, long w) {
            this.v = v;
            this.w = w;
        }

        public int compareTo(GraphPair o) {
            return w != o.w ? Long.compare(w, o.w) : Integer.compare(v, o.v);
        }
    }

    ArrayList<Integer>[] createGraph(int n) throws IOException {
        ArrayList<Integer>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++)
            graph[i] = new ArrayList<>();
        return graph;
    }

    ArrayList<GraphPair>[] createWeightedGraph(int n) throws IOException {
        ArrayList<GraphPair>[] graph = new ArrayList[n];
        for (int i = 0; i < n; i++)
            graph[i] = new ArrayList<>();
        return graph;
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s), 32768);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();
            return a;
        }

        int[][] nextIntTable(int n, int m) throws IOException {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    a[i][j] = in.nextInt();
            return a;
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextLong();
            return a;
        }

        long[][] nextLongTable(int n, int m) throws IOException {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    a[i][j] = in.nextLong();
            return a;
        }

        ArrayList<Integer>[] nextGraph(int n, int m, boolean directed) throws IOException {
            ArrayList<Integer>[] graph = createGraph(n);
            for (int i = 0; i < m; i++) {
                int v = in.nextInt() - 1, u = in.nextInt() - 1;
                graph[v].add(u);
                if (!directed)
                    graph[u].add(v);
            }
            return graph;
        }

        ArrayList<GraphPair>[] nextWeightedGraph(int n, int m, boolean directed) throws IOException {
            ArrayList<GraphPair>[] graph = createWeightedGraph(n);
            for (int i = 0; i < m; i++) {
                int v = in.nextInt() - 1, u = in.nextInt() - 1;
                long w = in.nextLong();
                graph[v].add(new GraphPair(u, w));
                if (!directed)
                    graph[u].add(new GraphPair(v, w));
            }
            return graph;
        }

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

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        for (int t = multitests ? in.nextInt() : 1; t-- > 0; )
            solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}