#include <bits/stdc++.h>
using namespace std;
const unsigned long long lim = 1e18;
unsigned long long x, a[10], b[10], l, r, mid;
int n;
void build() {
  unsigned long long r = 1;
  a[0] = b[0] = 0;
  for (unsigned long long i = 1; i <= 9; i++) {
    b[i] = b[i - 1] + 9 * r * i;
    a[i] = a[i - 1] + 9ll * r * b[i - 1] + (9 * r * (9 * r + 1)) / 2 * 1ll * i;
    r *= 10;
  }
}
void print(unsigned long long x) {
  if (x > 9) {
    unsigned long long i = 1, r = 1;
    while (x > 9 * i * r) {
      x -= 9 * i * r;
      i++, r *= 10;
    }
    unsigned long long kq = x % i;
    string tmp;
    if (kq == 0)
      tmp = to_string(r + (x / i) - 1);
    else
      tmp = to_string(r + (x / i));
    if (kq == 0)
      printf("%c\n", tmp.back());
    else
      printf("%c\n", tmp[kq - 1]);
  } else
    printf("%I64d\n", x);
}
int main() {
  build();
  scanf("%d", &n);
  while (n--) {
    scanf("%I64d", &x);
    int vt1 = (lower_bound(a, a + 10, x) - a);
    unsigned long long vt2;
    x -= a[vt1 - 1];
    l = 0;
    r = 9 * trunc(exp(log(10) * (unsigned long long)(vt1 - 1)));
    while (l <= r) {
      mid = l + ((r - l) >> 1);
      unsigned long long tmp = mid * b[vt1 - 1] + (mid * (mid + 1)) / 2 * vt1;
      if (tmp < x) {
        l = mid + 1;
        vt2 = tmp;
      } else {
        if (mid)
          r = mid - 1;
        else
          break;
      }
    }
    x -= vt2;
    print(x);
  }
  return 0;
}
