#include <bits/stdc++.h>
using namespace std;
void ECHO(string _s) {
  cout << endl;
  (void)_s;
}
template <typename T, typename... Args>
void ECHO(string _s, T x, Args... args) {
  unsigned _i;
  string _s2 = "";
  for (_i = 0; _i < _s.length(); ++_i) {
    if (_s[_i] == ',') break;
    if (_s[_i] != ' ') _s2 += _s[_i];
  }
  if (_i == _s.length()) {
    --_i;
  }
  cout << "  (" << _s2 << "):" << x;
  ECHO(_s.substr(_i + 1, _s.length() - _i - 1), args...);
}
template <typename T0, typename T1>
inline ostream& operator<<(ostream& os, pair<T0, T1>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
  for (unsigned i = 0; i < v.size(); ++i) {
    cout << v[i] << "_";
  }
  cout << endl;
  return os;
}
template <typename T>
inline T _min(T x1, T x2, T x3) {
  return min(x1, min(x2, x3));
}
template <typename T>
inline T _min(T x1, T x2, T x3, T x4) {
  return min(min(x1, x2), min(x2, x3));
}
inline long long _gcd(long long a, long long b) {
  while (b) b %= a ^= b ^= a ^= b;
  return a;
}
long long prevsum[] = {0,
                       45,
                       9045,
                       1395495,
                       189414495,
                       23939649495,
                       2893942449495,
                       339393974949495,
                       38939394344949495,
                       4393939398494949495};
long long prevres[] = {0,         9,          189,        2889,
                       38889,     488889,     5888889,    68888889,
                       788888889, 8888888889, 98888888869};
long long calculate(long long k) {
  if (!k) return 0;
  if (k == 1) return 1;
  int dig = (int)ceil(log10(k + 1));
  long long bas = pow(10, dig - 1);
  long long prev = prevres[dig - 1];
  long long res =
      ((k - bas + 1) * (prev) + dig * ((k - bas + 1) * (k - bas + 2)) / 2);
  return res + prevsum[dig - 1];
}
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long r = 999999999ll;
    long long l = 0;
    while (r - l > 1) {
      long long mid = (r + l) / 2;
      if (calculate(mid) < k)
        l = mid;
      else
        r = mid;
    }
    long long target = r;
    k -= calculate(target - 1);
    int dig = 1;
    while (k - prevres[dig] > 0) dig++;
    long long increment = -1;
    if (dig) {
      k -= prevres[dig - 1];
      increment = (k - 1) / dig;
      k -= increment * dig;
    }
    string a = to_string((long long)pow(10, dig - 1) + increment);
    cout << a[k - 1] << "\n";
  }
  return 0;
}
