#include <bits/stdc++.h>
using namespace std;
long long check(long long x) {
  long long temp = 0;
  long long kk = 1;
  while (kk <= x) {
    long long sm = x - kk + 1;
    temp += (sm * sm + sm) / 2;
    kk *= 10;
  }
  return temp;
}
long long get(long long x) {
  long long temp = 0;
  long long kk = 1;
  while (kk <= x) {
    long long sm = x - kk + 1;
    temp += sm;
    kk *= 10;
  }
  return temp;
}
void nikal_pehli_fursat_mai() {
  long long k;
  cin >> k;
  long long low = 1, high = 1e9;
  while (low < high) {
    long long mid = (low + high) / 2;
    if (check(mid) >= k)
      high = mid;
    else
      low = mid + 1;
  }
  if (check(low) == k) {
    cout << low % 10 << "\n";
    return;
  }
  k -= check(--low);
  high = k, low = 1;
  while (low < high) {
    long long mid = (low + high) / 2;
    if (get(mid) >= k)
      high = mid;
    else
      low = mid + 1;
  }
  if (k == get(low)) {
    cout << low % 10 << "\n";
    return;
  }
  int ans;
  long long extra = get(low) - k;
  for (int i = 0; i < extra + 1; i++) {
    ans = low % 10;
    low /= 10;
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    nikal_pehli_fursat_mai();
  }
}
