#include <bits/stdc++.h>
using namespace std;
unsigned long long t, n, a[105], tot;
inline void swp(unsigned long long &x, unsigned long long &y) {
  unsigned long long t = x;
  x = y;
  y = t;
  return;
}
inline unsigned long long asks(unsigned long long k) {
  unsigned long long len = 1, now = 9, ans = 0;
  while (k > 0) {
    unsigned long long tmp = 0;
    if (k <= now) {
      tmp = k * (k + 1) / 2;
      now *= 10, k = 0;
    } else {
      tmp = now * (now + 1) / 2;
      k -= now;
      tmp += k * now;
    }
    if (tmp >= 2000000000000000000 / len) return 2000000000000000000;
    ans += tmp * len;
    if (ans >= 2000000000000000000) return 2000000000000000000;
    len++, now *= 10;
  }
  return ans;
}
inline unsigned long long asknum(unsigned long long k) {
  unsigned long long len = 1, now = 9, ans = 0;
  while (k > 0) {
    if (k <= now) {
      ans += len * k;
      k = 0;
    } else {
      ans += len * now;
      k -= now;
      len++, now *= 10;
    }
  }
  return ans;
}
inline unsigned long long erfen1(unsigned long long now) {
  unsigned long long l = 1, r = 1e18, ans = 0;
  while (l <= r) {
    unsigned long long mid = (l + r) / 2;
    if (asks(mid) < now)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
inline unsigned long long erfen2(unsigned long long now) {
  unsigned long long l = 1, r = 1e18, ans = 0;
  while (l <= r) {
    unsigned long long mid = (l + r) / 2;
    if (asknum(mid) < now)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
signed main() {
  cin >> t;
  while (t--) {
    cin >> n;
    unsigned long long s = erfen1(n);
    n -= asks(s);
    unsigned long long k = erfen2(n);
    n -= asknum(k);
    k++;
    tot = 0;
    while (k > 0) a[++tot] = k % 10, k /= 10;
    for (unsigned long long i = 1; i <= tot / 2; i++) swp(a[i], a[tot - i + 1]);
    cout << a[n] << endl;
  }
  return 0;
}
