#include <bits/stdc++.h>
using namespace std;
struct NumericalSequence {
  int digits(int n) {
    int len = 0;
    while (n) {
      len++;
      n /= 10;
    }
    return len;
  }
  long long full_sequence_length(long long n) {
    long long len = digits(n);
    long long count = n + 1;
    long long ten = 1LL;
    long long answer = len * count * (count + 1LL) / 2LL;
    while (ten <= n) {
      answer -= count * ten - ten * (ten - 1LL) / 2LL;
      ten *= 10LL;
    }
    return answer;
  }
  long long part_sequence_length(long long n) {
    long long ans = 0LL;
    long long ten = 1LL;
    while (ten <= n) {
      ans += n - ten + 1;
      ten *= 10;
    }
    return ans;
  }
  long long solve(long long n) {
    long long le = 0, ri = (long long)(5e8);
    long long limit;
    while (le < ri) {
      long long mid = (le + ri + 1LL) / 2LL;
      limit = full_sequence_length(mid);
      if (limit >= n) {
        ri = mid - 1;
      } else {
        le = mid;
      }
    }
    limit = full_sequence_length(le);
    n -= limit;
    ri = le + 1;
    le = 1;
    while (le < ri) {
      long long mid = (le + ri) / 2LL;
      limit = part_sequence_length(mid);
      if (limit < n) {
        le = mid + 1;
      } else {
        ri = mid;
      }
    }
    limit = part_sequence_length(le);
    while (limit > n) {
      le /= 10;
      limit--;
    }
    return le % 10;
  }
};
int main() {
  cin.tie(NULL);
  NumericalSequence solution;
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    cout << solution.solve(k) << endl;
  }
  return 0;
}
