#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  x = ch - 48;
  while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
  return x;
}
long long T, k;
inline long long check(long long mid, bool f) {
  long long ans = 0, tmp = 0, len = 0, x = 1, cnt;
  bool flag = 1;
  while (flag) {
    x *= 10, len++;
    if (mid > x - 1)
      cnt = x - x / 10;
    else
      cnt = mid - x / 10 + 1, flag = 0;
    if (f)
      ans += tmp * cnt + cnt * (cnt + 1) / 2 * len, tmp += cnt * len;
    else
      ans += cnt * len;
  }
  return ans;
}
int main() {
  T = read();
  while (T--) {
    k = read();
    long long l = 0, r = 1e9, ans;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (check(mid, 1) < k)
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    k -= check(ans, 1);
    l = 0, r = ans + 1;
    while (l <= r) {
      long long mid = l + r >> 1;
      if (check(mid, 0) < k)
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    k -= check(ans, 0), ans++;
    printf("%c\n", to_string(ans)[k - 1]);
  }
  return 0;
}
