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.
#include <bits/stdc++.h>
using namespace std;
inline bool checkBit(long long n, long long i) {
  return n & ((long long)1 << i);
}
inline long long setBit(long long n, long long i) {
  return n | ((long long)1 << i);
  ;
}
inline long long resetBit(long long n, long long i) {
  return n & (~((long long)1 << i));
}
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) { a = (a + 1000000007) % 1000000007; }
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInv(long long a) { return modPow(a, 1000000007 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInv(b));
}
inline long long fact(long long r) {
  long long ans = 1;
  while (r) ans = modMul(ans, r), r--;
  return ans;
}
inline long long invfact(long long r) {
  long long ans = 1;
  while (r) ans = modMul(ans, modInv(r)), r--;
  return ans;
}
inline double dgcd(double a, double b) {
  if (a < b) return dgcd(b, a);
  if (b < .0001) return a;
  return dgcd(b, fmod(a, b));
}
long long k, flag;
long long check1(long long n, long long sum) {
  long long ans = sum, x = 0;
  for (long long i = 0; i < 10; i++) {
    if (x < n) ans += n - x;
    x += (long long)9 * (long long)pow((long long)10, i);
  }
  if (ans < k) return 1;
  while (n) {
    if (ans == k) {
      cout << n % 10 << endl;
      flag = 0;
      return 1;
    }
    n /= 10;
    ans--;
  }
  return 0;
}
bool check(long long n) {
  long long x = 0, sum = 0, m;
  for (long long i = 0; (long long)pow((long long)10, i) <= n; i++) {
    if (x <= n) sum += (n - x + 1) * (n - x) / 2;
    x += (long long)9 * (long long)pow((long long)10, i);
  }
  long long temp = sum;
  m = n;
  while (n) {
    if (temp == k) {
      cout << n % 10 << endl;
      flag = 0;
      return 1;
    }
    n /= 10;
    temp--;
  }
  if (sum > k) return 0;
  long long s = 1, e = m + 1;
  while (s <= e) {
    long long mid = (s + e) / 2;
    if (check1(mid, sum))
      s = mid + 1;
    else
      e = mid - 1;
    if (!flag) return 1;
  }
  return 1;
}
void solve() {
  flag = 1;
  cin >> k;
  long long s = 1, e = 1e9;
  while (s <= e) {
    long long mid = (s + e) / 2;
    if (check(mid) && flag)
      s = mid + 1;
    else if (flag)
      e = mid - 1;
    else
      return;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
