#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 5;
const int MOD = 1e9;
const long long ooll = 1e18 + 5;
const int N = 1e6 + 5;
const int lgN = 18;
long long below(long long n) {
  long long pw = 1;
  long long s = 0, ss = 0, ans = 0;
  int i = 1;
  while (pw * 10 - 1 < n) {
    s = i * pw * 9;
    ss = i * ((9 * pw * (11 * pw - 1)) / 2);
    pw *= 10;
    ans += n * s - ss;
    i++;
  }
  ans += n * (n - pw) * i - (((n - pw) * (pw + n - 1)) / 2) * i;
  return ans;
}
long long below2(long long n) {
  int i = 1;
  long long pw = 1, ans = 0, s = 0;
  while (pw * 10 - 1 < n) {
    ans += 9 * pw * i;
    ++i;
    pw *= 10;
  }
  ans += (n - pw) * i;
  return ans;
}
int getdig(long long n, int d) {
  vector<int> dig;
  while (n > 0) {
    dig.push_back(n % 10);
    n /= 10;
  }
  reverse(dig.begin(), dig.end());
  return dig[d];
}
void solve() {
  long long n;
  cin >> n;
  n--;
  long long lo = 1, hi = 1e9;
  while (lo < hi - 1) {
    long long mid = (lo + hi) >> 1;
    if (below(mid) <= n)
      lo = mid;
    else
      hi = mid;
  }
  if (below(hi) <= n) lo = hi;
  n -= below(lo);
  hi = lo;
  lo = 1;
  while (lo < hi - 1) {
    long long mid = (lo + hi) >> 1;
    if (below2(mid) <= n)
      lo = mid;
    else
      hi = mid;
  }
  if (below2(hi) <= n) lo = hi;
  n -= below2(lo);
  cout << getdig(lo, n) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  for (int tc = 1; tc <= t; ++tc) {
    solve();
  }
  return 0;
}
