#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000000000 - 1;
long long mpow(long long a, long long b) {
  long long ans = 1;
  for (long long i = 0; i < b; ++i) ans *= a;
  return ans;
}
long long len(long long k) {
  if (k >= 1 && k <= 9)
    return 1;
  else if (k >= 10 && k <= 99)
    return 2;
  else if (k >= 100 && k <= 999)
    return 3;
  else if (k >= 1000 && k <= 9999)
    return 4;
  else if (k >= 10000 && k <= 99999)
    return 5;
  else if (k >= 100000 && k <= 999999)
    return 6;
  else if (k >= 1000000 && k <= 9999999)
    return 7;
  else if (k >= 10000000 && k <= 99999999)
    return 8;
  else if (k >= 100000000 && k <= 999999999)
    return 9;
  else if (k >= 1000000000 && k <= 9999999999)
    return 10;
}
long long p[20];
void getp() {
  p[0] = 0;
  for (long long i = 1; i <= 9; ++i) {
    p[i] = p[i - 1] + i * 9 * (long long)mpow(10, i - 1);
  }
}
long long k[20];
void getk() {
  k[0] = 0;
  for (long long i = 1; i <= 9; ++i) {
    long long tmp = mpow(10, i - 1);
    k[i] = k[i - 1] + (p[i - 1] - i * (tmp - 1)) * 9 * tmp +
           9 * i * tmp * (tmp + tmp * 10 - 1) / 2;
  }
}
long long fp(long long i) {
  long long tmp = len(i);
  return p[tmp - 1] + (i - mpow(10, tmp - 1) + 1) * (tmp);
}
long long fk(long long i) {
  long long ilen = len(i);
  long long base = mpow(10, ilen - 1);
  return k[ilen - 1] + (p[ilen - 1] - ilen * (base - 1)) * (i - base + 1) +
         (((base + i) * (i - base + 1)) / 2) * ilen;
}
int main() {
  getp();
  getk();
  long long q;
  scanf("%lld", &q);
  for (long long i = 0; i < q; ++i) {
    long long a;
    scanf("%lld", &a);
    long long l = 1, r = maxn;
    while (l < r) {
      long long mid = r - (r - l) / 2;
      long long tmp = fk(mid);
      if (tmp <= a)
        l = mid;
      else
        r = mid - 1;
    }
    long long pre = fk(l);
    if (pre == a) {
      printf("%lld\n", l % 10);
    } else {
      a -= pre;
      l = 1, r = maxn;
      while (l < r) {
        long long mid = r - (r - l) / 2;
        long long tmp = fp(mid);
        if (tmp <= a)
          l = mid;
        else
          r = mid - 1;
      }
      long long pre1 = fp(l);
      if (pre1 == a) {
        printf("%lld\n", l % 10);
      } else {
        a -= pre1;
        long long k = len(l + 1);
        l++;
        for (long long i = 0; i < k - a; ++i) l /= 10;
        printf("%lld\n", l % 10);
      }
    }
  }
  return 0;
}
