#include <bits/stdc++.h>
using i64 = long long;
std::vector<i64> a{-100, 0};
i64 calc(i64 x) {
  i64 ten = 10, s = 0, j = 1;
  while (ten <= x) {
    i64 lb = ten / 10, ub = ten - 1;
    s += j * (ub + lb) * (ub - lb + 1) / 2 - a[j] * (ub - lb + 1);
    ten *= 10;
    j++;
  }
  i64 lb = ten / 10;
  s += j * (x + lb) * (x - lb + 1) / 2 - a[j] * (x - lb + 1);
  return s;
}
i64 calc2(i64 x) {
  i64 j = 1, ten = 10;
  while (ten <= x) {
    ten *= 10;
    j++;
  }
  return j * x - a[j];
}
int main() {
  constexpr i64 inf = 1000000000;
  int q;
  std::cin >> q;
  i64 ten = 10;
  while (true) {
    i64 next = a.back() + ten - 1;
    if (next > 1000000000000000000) break;
    a.push_back(next);
    ten *= 10;
  }
  while (q--) {
    i64 k;
    std::cin >> k;
    i64 l = 0, r = inf;
    while (r - l > 1) {
      i64 mid = (l + r) / 2;
      if (calc(mid) < k)
        l = mid;
      else
        r = mid;
    }
    i64 rem = k - calc(l);
    r = l + 1;
    l = 0;
    while (r - l > 1) {
      i64 mid = (l + r) / 2;
      if (calc2(mid) < rem)
        l = mid;
      else
        r = mid;
    }
    i64 ri = rem - calc2(l);
    std::cout << std::to_string(l + 1)[ri - 1] << std::endl;
  }
  return 0;
}
