#include <bits/stdc++.h>
using namespace std;
const int maxn = 15, maxx = 10;
long long a[maxn], b[maxn], c[maxn];
void Init() {
  for (int i = 1; i <= maxx; i++) {
    long long x = i, l = 1, r = 0;
    while (x--) l *= 10, r = r * 10 + 9;
    l /= 10;
    a[i] = (r - l + 1) * i;
    b[i] = b[i - 1] + a[i];
    c[i] = c[i - 1] + (b[i - 1] + i + b[i]) * (r - l + 1) / 2;
  }
}
int main() {
  ios::sync_with_stdio(0);
  Init();
  long long t, n, pos;
  cin >> t;
  while (t--) {
    cin >> n;
    pos = lower_bound(c + 1, c + maxx + 1, n) - c;
    n = n - c[pos - 1];
    long long l = 1, r = 0, x = pos, t = b[pos - 1];
    while (x--) l *= 10, r = 10 * r + 9;
    l /= 10;
    long long L = l;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long cnt = mid - L + 1;
      if ((2 * t + pos + cnt * pos) * cnt / 2 >= n)
        r = mid - 1;
      else
        l = mid + 1;
    }
    long long cnt = l - L;
    n -= (2 * t + pos + cnt * pos) * cnt / 2;
    pos = lower_bound(b + 1, b + maxx + 1, n) - b;
    n -= b[pos - 1];
    int ans = 1;
    for (int i = 1; i < pos; i++) ans *= 10;
    t = (n - 1) / pos;
    n -= t * pos;
    ans += t;
    n = pos - n;
    while (n--) ans /= 10;
    cout << ans % 10 << endl;
  }
  return 0;
}
