#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
vector<long long> bd;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long curSum = 0;
  long long digitCnt = 1;
  long long numCnt = 9;
  bd.push_back(0);
  for (int i = 0; i < 9; i++) {
    long long tmp = 0;
    long long nine = 9;
    for (long long i = 1; i < digitCnt; i++) {
      tmp += i * nine * numCnt;
      nine *= 10;
    }
    tmp += digitCnt * (numCnt * (numCnt + 1)) / 2;
    curSum += tmp;
    bd.push_back(curSum);
    digitCnt++;
    numCnt *= 10;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    long long k;
    cin >> k;
    auto it = lower_bound(bd.begin(), bd.end(), k);
    it--;
    long long idx = it - bd.begin();
    long long preSum = 0;
    long long nine = 9;
    for (long long i = 1; i <= idx; i++) {
      preSum += nine * i;
      nine *= 10;
    }
    long long curNum = 1;
    for (int i = 0; i < idx; i++) curNum *= 10;
    long long cnt = 1;
    long long curSum = *it;
    long long l = 0, r = nine;
    while (l < r) {
      long long mid = (l + r) / 2;
      long long val = mid * preSum + mid * (mid + 1) / 2 * (idx + 1);
      if (curSum + val < k)
        l = mid + 1;
      else
        r = mid;
    }
    r--;
    curSum += preSum * r + r * (r + 1) / 2 * (idx + 1);
    long long res_num = 1;
    long long last_cnt = 1;
    long long last_nine = 9;
    while (true) {
      long long plus = last_cnt * last_nine;
      if (curSum + plus >= k) break;
      curSum += plus;
      last_cnt++;
      last_nine *= 10;
      res_num *= 10;
    }
    long long div = (k - curSum) / last_cnt;
    if ((k - curSum) % last_cnt == 0) div--;
    res_num += div;
    curSum += div * last_cnt;
    int last_digit = k - curSum;
    vector<int> digit;
    while (res_num) digit.push_back(res_num % 10), res_num /= 10;
    reverse(digit.begin(), digit.end());
    cout << digit[last_digit - 1] << "\n";
  }
}
