#include <bits/stdc++.h>
using namespace std;
inline long long Calc(const int &x) {
  long long res = 0;
  for (long long i = 1; i <= x; i *= 10) res += x - i + 1;
  return res;
}
inline long long CalcSum(const int &x) {
  long long res = 0;
  for (long long i = 1; i <= x; i *= 10)
    res += 1ll * (x - i + 1) * (x - i + 2) / 2;
  return res;
}
inline int Pos(const int &x, const int &k) {
  stringstream ss;
  ss << x;
  string s;
  ss >> s;
  return s[k - 1] - '0';
}
inline int Solve(long long k) {
  int l = 1, r = 1000000000;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (CalcSum(mid) >= k)
      r = mid - 1;
    else
      l = mid + 1;
  }
  k = k - CalcSum(r);
  int block = l;
  l = 1;
  r = block;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (Calc(mid) >= k)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return Pos(l, k - Calc(r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    cout << Solve(k) << '\n';
  }
  return 0;
}
