#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
const long long MOD = 1e9 + 7;
inline long long add(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline long long mul(long long x, long long y) { return (x * 1ll * y) % mod; }
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 3e5 + 5;
inline void io() {}
long long sumtot(long long r, long long f) {
  long long sum = 0, add = 0;
  long long p = 1;
  for (long long i = 1;; i++) {
    if (p * 10 - 1 < r) {
      long long cnt = 10 * p - p;
      if (f) {
        sum += cnt * add + (cnt * (cnt + 1)) / 2 * i;
        add += i * cnt;
      } else {
        sum += cnt * i;
      }
    } else {
      long long cnt = r - p + 1;
      if (f) {
        sum += cnt * add + (cnt * (cnt + 1)) / 2 * i;
        add += cnt * i;
      } else
        sum += cnt * i;
      break;
    }
    p *= 10;
  }
  return sum;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    n--;
    long long l = 1, r = 1e9;
    long long res = -1;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (sumtot(mid, 1) > n) {
        res = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    n -= sumtot(res - 1, 1);
    l = 1, r = res;
    long long ans = -1;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (sumtot(mid, 0) > n) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    string s = to_string(ans);
    cout << s[n - sumtot(ans - 1, 0)] << endl;
  }
}
