#include <bits/stdc++.h>
using namespace std;
const int maxk = 11;
long long p[maxk];
void init() {
  p[0] = 1;
  for (int i = 1; i <= maxk; ++i) p[i] = p[i - 1] * 10;
}
long long f(long long x) {
  if (x == 0) return 0;
  long long ret = 0;
  int pc = maxk - 1;
  while (p[pc] > x) --pc;
  ret += (pc + 1) * (x - p[pc] + 1);
  while (pc > 0) {
    --pc;
    ret += (pc + 1) * (p[pc + 1] - p[pc]);
  }
  return ret;
}
typedef long long (*FUN)(long long);
long long bis(long long pos, FUN fun) {
  long long ans = 0;
  long long l = 0, r = 1000000000;
  while (l < r) {
    long long mid = l + (r - l) / 2;
    if (fun(mid) < pos)
      ans = mid, l = mid + 1;
    else
      r = mid;
  }
  return ans;
}
long long g(long long x) {
  if (x == 0) return 0;
  int pc = maxk - 1;
  while (p[pc] > x) --pc;
  long long ret = 0;
  ret += (pc + 1) * (x - p[pc] + 1) * (1 + x - p[pc] + 1) / 2;
  while (pc > 0) {
    --pc;
    ret += (pc + 1) * 9 * p[pc] * (x + x - (p[pc] - 1) - (p[pc + 1] - 2)) / 2;
  }
  return ret;
}
char cc[100000];
int main() {
  init();
  int q;
  long long k;
  scanf("%d", &q);
  long long temp = 0;
  while (q--) {
    scanf("%lld", &k);
    long long ans = bis(k, g);
    k -= g(ans);
    ans = bis(k, f);
    k -= f(ans);
    sprintf(cc, "%lld", ans + 1);
    printf("%c\n", cc[k - 1]);
  }
  getchar();
  getchar();
  return 0;
}
