#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
template <class T, class U>
using Pa = pair<T, U>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int Q;
  cin >> Q;
  auto check = []() {
    ll s = 0;
    for (int i = 1; i <= 99999; i++) {
      for (int j = 1; j <= i; j++) {
        int x = j;
        int c = 0;
        while (x) {
          c++;
          x /= 10;
        }
        s += c;
      }
    }
    cout << s << "\n";
  };
  int M = 18;
  vec<ll> pow10(M, 1);
  for (int i = 1; i < M; i++) {
    pow10[i] = pow10[i - 1] * 10;
  }
  auto length = [&](int x) {
    ll res = 0;
    for (int i = 0; i < M; i++) {
      if (pow10[i + 1] <= x)
        res += (i + 1) * (pow10[i + 1] - pow10[i]);
      else {
        res += (x - pow10[i] + 1) * (i + 1);
        break;
      }
    }
    return res;
  };
  auto digit = [&](int x, int n) {
    vec<int> v;
    while (x) {
      v.push_back(x % 10);
      x /= 10;
    }
    reverse(v.begin(), v.end());
    return v[n - 1];
  };
  vec<ll> sum(10);
  for (int i = 1; i <= 9; i++) {
    ll a = length(pow10[i - 1]);
    ll n = pow10[i] - pow10[i - 1];
    sum[i] = sum[i - 1] + a * n + n * (n - 1) / 2 * i;
    cerr << i << " " << sum[i] << "\n";
  }
  auto prefix_length = [&](ll x) {
    if (!x) return 0ULL;
    int c = 0;
    ll y = x;
    while (y) {
      c++;
      y /= 10;
    }
    ll res = sum[c - 1];
    ll a = length(pow10[c - 1]);
    ll n = x - pow10[c - 1] + 1;
    res += a * n + n * (n - 1) / 2 * c;
    return res;
  };
  auto ans = [&](ll k) {
    int l = 0, r = 2e9;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (prefix_length(m) < k)
        l = m;
      else
        r = m;
    }
    k -= prefix_length(l);
    int l2 = 0, r2 = r;
    while (l2 + 1 < r2) {
      int m = (l2 + r2) / 2;
      if (length(m) < k)
        l2 = m;
      else
        r2 = m;
    }
    return digit(r2, k - length(l2));
  };
  while (Q--) {
    ll k;
    cin >> k;
    cout << ans(k) << "\n";
  }
}
