#include <bits/stdc++.h>
using namespace std;
long long f[20];
long long g[20];
void init() {
  long long k = 9;
  for (long long i = 1; i <= 10; i++) {
    f[i] = f[i - 1] + i * k;
    k = k * 10;
  }
  k = 9;
  for (long long i = 2; i <= 10; i++) {
    g[i] = g[i - 1] + (f[i - 2] + i - 1 + f[i - 1]) * (k) / 2;
    k = k * 10;
  }
}
long long getsz(long long x) {
  long long c = 0, y = x;
  while (y) c++, y = y / 10;
  return c;
}
long long getv(long long c) {
  long long tmp = 0, k = 9;
  for (long long i = 1; i <= c - 1; i++) tmp += k, k = k * 10;
  return tmp;
}
long long get(long long x, long long sum) {
  long long c = getsz(x);
  long long tmp = getv(c);
  long long v = sum - g[c];
  long long sz = x - tmp;
  sz = (f[c - 1] + c + f[c - 1] + c * sz) * sz / 2;
  return sz - v;
}
long long get2(long long x, long long sum) {
  long long c = getsz(x);
  long long tmp = getv(c);
  long long v = sum - f[c - 1];
  long long sz = x - tmp;
  sz = c * (sz);
  return sz - v;
}
long long get3(long long x, long long cnt) {
  long long a[100], sz = 0;
  while (x) a[++sz] = x % 10, x = x / 10;
  return a[cnt + 1];
}
int main() {
  init();
  long long x;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    long long l = 1, r = 1e9;
    long long ans = 0, need = -1e12;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long k = get(mid, x);
      if (k <= 0) {
        l = mid + 1;
        if (k > need) need = k, ans = mid;
      } else {
        r = mid - 1;
      }
    }
    if (need == 0)
      printf("%lld\n", ans % 10);
    else {
      need = -need;
      l = 1, r = ans + 1;
      long long res = -1, up = 1e18;
      while (l <= r) {
        long long mid = (l + r) >> 1;
        long long k = get2(mid, need);
        if (k < 0)
          l = mid + 1;
        else {
          r = mid - 1;
          if (k <= up) up = k, res = mid;
        }
      }
      printf("%lld\n", get3(res, up));
    }
  }
  return 0;
}
