#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MAXN = 18;
ll sum(ll f, ll l, ll n) {
  if (n <= 0) return 0LL;
  return (n * (f + l)) >> 1;
}
ll g(ll t) {
  ll pot10 = 1LL, ans = 0LL;
  for (int i = (int)1; i < (int)100; ++i) {
    ll l = 9LL * pot10, m = 1 + t - pot10;
    if (pot10 * 10LL <= t) {
      ans += 1LL * i * l;
    } else {
      ans += 1LL * i * m;
      return ans;
    }
    pot10 *= 10LL;
  }
  assert(false);
}
int solve2(ll k) {
  int low = 0, high = 1e9, best = -1;
  while (low <= high) {
    int mid = (low + high) >> 1;
    if (g(mid) >= k) {
      high = mid - 1;
      best = mid;
    } else {
      low = 1 + mid;
    }
  }
  return to_string(best)[k - g(best - 1) - 1] - '0';
}
ll calc(ll t) {
  ll pot10 = 1LL, len = 0, ans = 0LL;
  for (int i = (int)1; i < (int)100; ++i) {
    len += i;
    ll l = 9LL * pot10, m = 1 + t - pot10;
    if (pot10 * 10LL <= t) {
      ans += sum(len, len + 1LL * i * (l - 1), l);
    } else {
      ans += sum(len, len + 1LL * i * (m - 1), m);
      return ans;
    }
    len += (i * (l - 1));
    pot10 *= 10LL;
  }
  assert(false);
}
int solve(ll k) {
  int low = 0, high = 1e9, best = -1;
  while (low <= high) {
    int mid = (low + high) >> 1;
    if (calc(mid) < k) {
      low = 1 + mid;
      best = mid;
    } else {
      high = mid - 1;
    }
  }
  assert(~best);
  return solve2(k - calc(best));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int q;
  cin >> q;
  while (q--) {
    ll k;
    cin >> k;
    cout << solve(k) << '\n';
  }
  return 0;
}
