#include <bits/stdc++.h>
using namespace std;
const int MAX = 98070;
int t;
long long k;
long long ap_sum(long long start, long long n) {
  return n * (2 * start - n + 1) / 2;
}
long long total_len(int x) {
  long long start = x, next10 = 10, len = 1;
  long long ans = 0;
  while (next10 <= x) {
    ans += len * ap_sum(start, next10 / 10 * 9);
    start -= next10 / 10 * 9;
    next10 *= 10;
    len++;
  }
  return ans + len * ap_sum(start, start);
}
long long one_more_bs(int x) {
  long long start = 1, len = 1, next10 = 10, ans = 0;
  while (next10 <= x) {
    ans += (next10 - start) * len;
    start *= 10;
    len++;
    next10 *= 10;
  }
  return ans + (x - start + 1) * len;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> k;
    int lo = 0, hi = 1e9, l;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      if (total_len(mid) < k)
        lo = mid + 1, l = mid;
      else
        hi = mid - 1;
    }
    k -= total_len(l);
    lo = 0, hi = l;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      if (one_more_bs(mid) < k)
        lo = mid + 1, l = mid;
      else
        hi = mid - 1;
    }
    k -= one_more_bs(l);
    cout << to_string(l + 1)[k - 1] << "\n";
  }
}
