#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<long long>;
using vvb = vector<vector<bool>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vpii = vector<pair<int, int>>;
using mii = map<int, int>;
template <typename... ArgTypes>
void print(ArgTypes... args);
template <typename... ArgTypes>
void input(ArgTypes &...args);
template <>
void print() {}
template <>
void input() {}
template <typename T, typename... ArgTypes>
void print(T t, ArgTypes... args) {
  cout << t;
  print(args...);
}
template <typename T, typename... ArgTypes>
void input(T &t, ArgTypes &...args) {
  cin >> t;
  input(args...);
}
long long prefix(long long seq) {
  long long now = 10000000000LL;
  long long res = 0LL;
  for (long long digit = 10LL; digit >= 1; digit--) {
    now /= 10LL;
    if (seq < now) continue;
    if (seq <= now * 10LL - 1LL)
      res += digit * (seq - now + 1LL) * (seq - now + 2LL) / 2LL;
    else {
      res += digit * (now * 10LL - now) * (now * 10LL - now + 1LL) / 2LL;
      res += digit * (now * 10LL - now) * (seq - now * 10LL + 1LL);
    }
  }
  return res;
}
long long a(long long seq) {
  long long now = 10000000000LL;
  long long res = 0LL;
  for (long long digit = 10LL; digit >= 1; digit--) {
    now /= 10LL;
    if (seq < now) continue;
    res += digit * (seq - now + 1LL);
    seq = now - 1LL;
  }
  return res;
}
int getDig(long long x, int y) {
  vi d;
  while (x) {
    d.push_back(x % 10LL);
    x /= 10LL;
  }
  return d[d.size() - y];
}
inline void _() {
  long long d;
  cin >> d;
  long long l = 1LL;
  long long r = 1000000000LL;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (prefix(mid) >= d)
      r = mid;
    else
      l = mid + 1LL;
  }
  long long pos = d - prefix(l - 1LL);
  l = 0LL;
  r = 1000000000LL;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (a(mid) >= pos)
      r = mid;
    else
      l = mid + 1LL;
  }
  cout << getDig(l, pos - a(l - 1LL)) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  int __;
  cin >> __;
  while (__--) _();
}
