#include <bits/stdc++.h>
using namespace std;
int n, q;
long long k;
long long ans = 0;
long long calc(long long n) {
  if (n <= 9) {
    return (n * (n + 1)) / 2;
  }
  long long p = 9;
  long long mx = 99;
  long long ans = (9LL * 10 / 2);
  ans += 9 * (n - 9);
  int d = 2;
  long long m = n;
  m -= 9;
  for (int j = 2; m; j++) {
    long long cnt = mx - p;
    cnt = min(cnt, m);
    m -= cnt;
    ans += cnt * (cnt + 1) / 2 * j;
    if (m) ans += j * cnt * (n - mx);
    p = mx;
    mx = mx * 10 + 9;
    d++;
  }
  return ans;
}
char calc2(long long n) {
  long long mx = 9;
  long long p = 0;
  long long number = 0;
  long long nxt = 10;
  int d = 0;
  for (int i = 1;; i++) {
    long long cc = mx - p;
    long long cnt = cc * i;
    d++;
    if (cnt < n) {
      n -= cnt;
      number = mx;
    } else {
      long long bef = n / i;
      number += bef;
      n %= i;
      number += (n != 0);
      break;
    }
    p = mx;
    mx = mx * 10 + 9;
    nxt *= 10;
  }
  return to_string(number)[(n + d - 1) % d];
}
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf(" %lld", &k);
    long long s = 1;
    long long e = 1e9;
    long long res = 0;
    int ii = 200;
    while (ii-- && s <= e) {
      long long md = s + (e - s) / 2;
      long long cc = calc(md);
      if (cc < k) {
        s = md + 1;
        res = cc;
      } else {
        e = md - 1;
      }
    }
    k -= res;
    char ans = calc2(k);
    printf("%c\n", ans);
  }
  return 0;
}
