#include <bits/stdc++.h>
int main() {
  int T;
  std::cin >> T;
  auto calFG = [](long long n) -> std::pair<long long, long long> {
    long long start = 0, d = 1, nines = 9, sum = 0, res = 0;
    for (; sum + nines < n; ++d, sum += nines, nines *= 10) {
      res += nines * start + nines * (nines - 1) / 2 * d;
      start += nines * d;
    }
    return {start + d * (n - sum),
            res + (n - sum + 1) * start + (n - sum + 1) * (n - sum) / 2 * d};
  };
  auto bFind = [](long long n,
                  const std::function<long long(int)>& func) -> int {
    int l = 0, r = INT_MAX - 10;
    while (l < r) {
      int mid = l + (r - l + 1) / 2;
      if (func(mid) < n) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }
    return l;
  };
  for (long long n; std::cin >> n;) {
    int ii =
        bFind(n, std::bind([&](int m) -> long long { return calFG(m).second; },
                           std::placeholders::_1));
    long long res = n - calFG(ii).second;
    int i =
        bFind(res, std::bind([&](int m) -> long long { return calFG(m).first; },
                             std::placeholders::_1));
    long long ress = res - calFG(i).first;
    assert(ress);
    std::cout << std::to_string(i + 1).at(ress - 1) << std::endl;
  }
  return 0;
}
