#include <bits/stdc++.h>
inline long long get_sum(long long x) { return x * (x + 1) / 2; }
inline long long calc_1(long long x) {
  long long ans = 0, i = 1, j = 1;
  for (; j * 10 <= x; i++, j *= 10) {
    ans += i * get_sum(j * 9) + i * j * 9 * (x - j * 10 + 1);
  }
  return ans + i * get_sum(x - j + 1);
}
inline long long calc_2(long long x) {
  long long ans = 0, i = 1, j = 1;
  for (; j * 10 <= x; i++, j *= 10) {
    ans += i * j * 9;
  }
  return ans + i * (x - j + 1);
}
int main() {
  long long q, k;
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld", &k);
    long long l = 0, r = 1e9, res1, res2;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (calc_1(mid) < k) {
        l = mid + 1;
        res1 = mid;
      } else
        r = mid - 1;
    }
    k -= calc_1(res1);
    l = 0, r = res1 + 1;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (calc_2(mid) < k) {
        l = mid + 1;
        res2 = mid;
      } else
        r = mid - 1;
    }
    k -= calc_2(res2++);
    int a[30];
    memset(a, 0, sizeof(a));
    int i = 0;
    while (res2) {
      a[++i] = res2 % 10;
      res2 /= 10;
    }
    printf("%d\n", a[i - k + 1]);
  }
  return 0;
}
