#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long test(long long n) {
  long long ret = 0, temp = n, x = 0;
  while (n) {
    ret += (temp - x) * (temp - x + 1) / 2;
    x *= 10;
    x += 9;
    n /= 10;
  }
  return ret;
}
long long totalDigits(long long n) {
  long long number_of_digits = 0;
  for (long long i = 1; i <= n; i *= 10) number_of_digits += (n - i + 1);
  return number_of_digits;
}
int sum(long long x) {
  int ret = 0;
  while (x) ret++, x /= 10;
  return ret;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long l = 0, r = 1e9, k, best = 0, totalCnt = 0;
    cin >> k;
    while (l <= r) {
      long long mid = (l + r) / 2;
      long long cnt = test(mid);
      if (cnt >= k) {
        totalCnt = cnt;
        best = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    long long temp = test(best - 1);
    k -= temp;
    totalCnt -= temp;
    l = 1, r = best;
    while (l <= r) {
      long long mid = (l + r) / 2;
      long long cnt = totalDigits(mid - 1);
      if (cnt < k && cnt + sum(mid) >= k) {
        k -= cnt;
        string num = to_string(mid);
        cout << num[k - 1] << endl;
        break;
      }
      if (cnt >= k) {
        r = mid - 1;
      } else
        l = mid + 1;
    }
  }
}
