#include <bits/stdc++.h>
using namespace std;
unsigned long long p[19];
stack<unsigned long long> st;
unsigned long long fun(unsigned long long n) {
  unsigned long long cnt = 0;
  while (n) {
    cnt++;
    n /= 10;
  }
  return cnt;
}
unsigned long long eval(unsigned long long num, unsigned long long dig) {
  while (!st.empty()) st.pop();
  unsigned long long k;
  while (num) {
    st.push(num % 10);
    num /= 10;
  }
  for (unsigned long long i = 0; i < dig; i++) {
    k = st.top();
    st.pop();
    if (i == dig - 1) return k;
  }
}
unsigned long long fun2(unsigned long long n) {
  unsigned long long i, j, k, m, ans = 45, dig = 2, t = 99, c = 90, p, cnt;
  if (n <= 9) {
    return ((n * (n + 1)) / 2);
  }
  ans = 9 * (2 * n - 8);
  ans /= 2;
  for (i = 1; i <= 18; i++) {
    if (n <= t) {
      cnt = n - (t / 10);
      p = cnt * ((n - (t / 10)) + 1) * dig;
      dig++;
      p /= 2;
      ans += p;
      return ans;
    } else if (n > t) {
      cnt = c;
      p = cnt * ((n - (t / 10)) + (n - t + 1)) * dig;
      dig++;
      p /= 2;
      ans += p;
      c *= 10;
      t *= 10;
      t += 9;
    }
  }
}
int main() {
  unsigned long long i, j, k, n, prev, cnt, c, ind, l, r, mid, ni, val, num,
      dig, t, len1, len2, len;
  prev = 1;
  ni = 9;
  for (i = 1; i <= 18; i++) {
    p[i] = p[i - 1] + ((i)*ni);
    ni *= 10;
  }
  cin >> t;
  while (t--) {
    cin >> n;
    l = 1;
    r = 500000000;
    ind = -1;
    while (l < r) {
      mid = l + (r - l) / 2;
      if (l + 1 == r) {
        len1 = fun2(l);
        len2 = fun2(r);
        if (n == len1) {
          ind = l;
          break;
        } else {
          ind = r;
          break;
        }
      }
      len = fun2(mid);
      if (n == len) {
        ind = mid;
        break;
      } else if (n > len)
        l = mid;
      else
        r = mid;
    }
    val = n - fun2(ind - 1);
    c = 0;
    for (i = 1; i < 19; i++) {
      if (val <= p[i]) {
        val = val - p[i - 1];
        num = c + ((val + i - 1) / i);
        dig = val % i;
        if (!dig) dig = i;
        break;
      }
      c *= 10;
      c += 9;
    }
    cout << eval(num, dig) << "\n";
  }
}
