#include <bits/stdc++.h>
using namespace std;
unsigned long long n, p10[19] = {1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= 18; ++i) p10[i] = 10 * p10[i - 1];
  int T;
  for (cin >> T; T--;) {
    cin >> n;
    unsigned long long lo = 0, hi = 1e9, mid, done = 0;
    while (lo < hi) {
      mid = lo + hi + 1 >> 1;
      unsigned long long digits = 0;
      int len = 0;
      for (unsigned long long now = mid; now; now /= 10, ++len)
        ;
      digits = len * mid * (mid + 1) / 2;
      for (int i = 1; i < len; ++i) {
        unsigned long long r = mid, l = mid - p10[i] + 1;
        digits -= r * (r + 1) / 2 - l * (l + 1) / 2;
      }
      if (digits < n) {
        done = digits;
        lo = mid;
      } else {
        hi = mid - 1;
      }
    }
    unsigned long long rem = n - done;
    int ans = -1;
    for (int i = 1; i <= 18; ++i) {
      if (rem > i * (p10[i] - p10[i - 1]))
        rem -= i * (p10[i] - p10[i - 1]);
      else {
        --rem;
        cout << to_string(p10[i - 1] + rem / i)[rem % i] << '\n';
        break;
      }
    }
  }
}
