#include <bits/stdc++.h>
using namespace std;
long long pot10[1 << 5], n, q, k, x, b, l, t;
long long sumto(long long n, int op) {
  long long sum = 0LL;
  for (long long idx = 0; n >= pot10[idx]; ++idx) {
    long long digs = (n - (pot10[idx] - 1));
    sum += (op ? (digs * (digs + 1)) / 2 : digs);
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  pot10[0] = 1;
  for (int(i) = (1); (i) <= (18); ++(i)) {
    pot10[i] = pot10[i - 1] * 10;
  }
  while (cin >> q) {
    while (q--) {
      cin >> k;
      long long lo = 1LL, hi = 5e8;
      while (lo < hi) {
        long long mid = lo + (hi - lo) / 2;
        if (sumto(mid, 1) >= k)
          hi = mid;
        else
          lo = mid + 1;
      }
      k -= sumto(lo - 1, 1);
      b = lo;
      lo = 1LL, hi = b;
      while (lo < hi) {
        long long mid = lo + (hi - lo) / 2;
        if (sumto(mid, 0) >= k)
          hi = mid;
        else
          lo = mid + 1;
      }
      k -= sumto(lo - 1, 0);
      n = lo;
      t = log10(n) + 1;
      for (int(i) = (1); (i) <= (t - k); ++(i)) {
        n /= 10;
      }
      cout << (n % 10) << '\n';
    }
    cout << '\n';
  }
  return 0;
}
