#include <bits/stdc++.h>
using namespace std;
long long a[18] = {0};
long long dig(long long n) {
  if (n == 0) return 0;
  long long d = floor(log10(n)) + 1;
  long long ans = 0, p = 9, m = n;
  for (int i = 1; i < d; i++) {
    ans += i * p;
    m -= p;
    p *= 10;
  }
  ans = ans + d * m;
  return ans;
}
long double digupton(long long n) {
  if (n == 0) return 0;
  long long d = floor(log10(n)) + 1;
  long double sum = 0, p = 9, m = n;
  for (int i = 1; i < d; i++) {
    long double x = (p * (2 * a[i] + (p - 1) * i)) / 2.0;
    assert(x > 0);
    sum += x;
    m -= p;
    p *= 10;
  }
  sum += (m * (2 * a[d] + (m - 1) * d)) / 2;
  return sum;
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  for (long i = 0; i < 17; i++) {
    a[i + 1] = dig(pow(10, i));
  }
  while (t--) {
    long long n;
    cin >> n;
    long long st = 0, en = 1e12, mid, ans = -1, m;
    while (st <= en) {
      mid = (st + en) / 2;
      if (digupton(mid) >= n) {
        en = mid - 1;
      } else {
        m = n - digupton(mid);
        ans = mid;
        st = mid + 1;
      }
    }
    n = ans + 1;
    long long d = floor(log10(n)) + 1;
    ans = 0;
    long long p = 9, i;
    for (i = 1; m > p * i && i < d; i++) {
      m -= p * i;
      p *= 10;
    }
    d = i;
    long long f = pow(10, d - 1), dig;
    if (m % d == 0) {
      f += (m - 1) / d;
      dig = 0;
    } else {
      f += m / d;
      dig = d - m % d;
    }
    ans = 0;
    do {
      ans = f % 10;
      dig--;
      f /= 10;
    } while (dig >= 0);
    cout << ans << "\n";
  }
  return 0;
}
