#include <bits/stdc++.h>
using pii = std::pair<long long, long long>;
using namespace std;
long long t, k;
long long check(long long x) {
  long long cnt = 0, sub = 9;
  while (x > 0) {
    cnt += (x * (x + 1)) / 2;
    x -= sub;
    sub *= 10;
  }
  return cnt <= k;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  for (long long cases = 0; cases < t; cases++) {
    cin >> k;
    long long lo = 1, hi = 1e9, mid;
    while (lo < hi) {
      mid = (lo + hi + 1) / 2;
      if (check(mid))
        lo = mid;
      else
        hi = mid - 1;
    }
    assert(lo == hi);
    long long sub = 9;
    while (lo > 0) {
      k -= (lo * (lo + 1)) / 2;
      lo -= sub;
      sub *= 10;
    }
    if (!k)
      cout << hi % 10 << "\n";
    else {
      k--;
      long long step = 1, cnt = 9;
      while (k >= step * cnt) {
        k -= step * cnt;
        step++;
        cnt *= 10;
      }
      long long num = 1;
      for (long long i = 1; i < step; i++) num *= 10;
      long long take = k / step, opprem = (step - 1) - (k % step);
      num += take;
      while (opprem > 0) {
        num /= 10;
        opprem--;
      }
      cout << num % 10 << "\n";
    }
  }
  return 0;
}
