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.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
template <typename Head>
void dump_1(const char* str, Head&& h) {
  cerr << str << ": " << h << '\n';
}
template <typename Head, typename... Tail>
void dump_1(const char* str, Head&& h, Tail&&... t) {
  while (*str != ',') {
    cerr << *str++;
  }
  cerr << ": " << h << ' ';
  dump_1(str + 1, t...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << '(' << v.first << ", " << v.second << ')';
  return os;
}
template <typename T1, typename T2, typename T3>
ostream& operator<<(ostream& os, const tuple<T1, T2, T3>& v) {
  os << '(' << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ')';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ' ';
    }
    os << *it;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ' ';
    }
    os << *it;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ' ';
    }
    os << *it;
  }
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& v) {
  os << '{';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ", ";
    }
    os << it->first << ':' << it->second;
  }
  os << '}';
  return os;
}
void Yes(void) { cout << "Yes" << '\n'; }
void No(void) { cout << "No" << '\n'; }
void YES(void) { cout << "YES" << '\n'; }
void NO(void) { cout << "NO" << '\n'; }
template <typename T>
void chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
  }
}
template <typename T>
void chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
  }
}
template <typename T>
void vin(vector<T>& v, ll len) {
  for (ll i = 0; i < (len); i++) {
    cin >> v[i];
  }
}
template <typename Head>
void in_1(Head& h) {
  cin >> h;
}
template <typename Head, typename... Tail>
void in_1(Head& h, Tail&... t) {
  cin >> h;
  in_1(t...);
}
template <typename Head>
void print_1(Head&& h) {
  cout << h << '\n';
}
template <typename Head, typename... Tail>
void print_1(Head&& h, Tail&&... t) {
  cout << h << ' ';
  print_1(t...);
}
ll f(ll n) {
  if (n <= 9) {
    return n;
  }
  ll keta = 1;
  for (ll i = 100; i <= 1e18; i *= 10) {
    ll i9 = i - 1;
    ++keta;
    if (n <= i9) {
      ll i0 = i / 10 - 1;
      return f(i0) + (n - i0) * keta;
    }
  }
  return 0;
}
ll calc(ll n) {
  if (n <= 9) {
    ll a = 1;
    ll d = 1;
    return (a + a + (n - 1) * d) * n / 2;
  }
  ll keta = 1;
  for (ll i = 100; i <= 1e18; i *= 10) {
    ll i9 = i - 1;
    ++keta;
    if (n <= i9) {
      ll i0 = i / 10 - 1;
      ll a = f(i0) + keta;
      ll d = keta;
      n -= i0;
      return calc(i0) + (a + a + (n - 1) * d) * n / 2;
    }
  }
  return 0;
}
string f2(ll n) {
  ll max1 = 10;
  ll keta = 2;
  while (n >= f(max1 - 1)) {
    max1 *= 10;
    keta++;
  }
  keta--;
  if (keta == 1) {
    return to_string(n + 1);
  }
  max1 /= 10;
  n -= f(max1 - 1);
  ll a = max1 + n / keta;
  return to_string(a).substr(n % keta, 1);
}
void solve() {
  ll Q;
  in_1(Q);
  for (ll q = 0; q < (Q); q++) {
    ll x;
    in_1(x);
    if (x == 1) {
      print_1(1);
      continue;
    }
    ll lo = 1;
    ll hi = 1000000000000;
    ll val = 0;
    while (hi - lo > 1) {
      ll mi = lo + (hi - lo) / 2;
      val = calc(mi);
      if (val > x) {
        hi = mi;
      } else {
        lo = mi;
      }
    }
    val = calc(lo);
    if (x == val) {
      string s = to_string(lo);
      print_1(s.substr(s.length() - 1, 1));
    } else {
      print_1(f2(x - val - 1));
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  solve();
}
