#include <bits/stdc++.h>
using namespace std;
long long a[1005], b[1005];
long long _pow(long long aa, long long nn) {
  long long ans = 1;
  while (nn) {
    if (nn & 1) ans = (ans * aa);
    aa = (aa * aa);
    nn >>= 1;
  }
  return ans;
}
int getnum(int i) { return _pow(10, i) - _pow(10, i - 1); }
long long getc(long long s) {
  long long w = 0;
  while (s) {
    w++;
    s /= 10;
  }
  return w == 0 ? 1 : w;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  for (long long i = 1; i <= 9; i++) {
    long long num = getnum(i);
    a[i] = a[i - 1] + num * i;
    b[i] = b[i - 1] + (a[i - 1] + i) * num + (num - 1) * num / 2 * i;
  }
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    int k = 1;
    for (int i = 1; i <= 9; i++) {
      if (b[i] >= n) {
        k = i;
        break;
      }
    }
    long long l = 1, r = getnum(k);
    long long ans = 0;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long sum = b[k - 1] + (a[k - 1] + k) * mid + (mid - 1) * mid / 2 * k;
      if (sum < n) {
        l = mid + 1;
      } else {
        ans = mid;
        r = mid - 1;
      }
    }
    n -= b[k - 1] + (a[k - 1] + k) * (ans - 1) + (ans - 2) * (ans - 1) / 2 * k;
    l = 1, r = ans + _pow(10, k - 1) - 1;
    long long vs;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long len = getc(mid);
      long long sum = a[len - 1] + (mid - _pow(10, len - 1) + 1) * len;
      if (sum < n) {
        l = mid + 1;
      } else {
        vs = mid;
        r = mid - 1;
      }
    }
    long long len = getc(vs - 1);
    long long sum = a[len - 1] + (vs - _pow(10, len - 1)) * len;
    ans = vs;
    n -= sum;
    int s;
    n = getc(ans) - n + 1;
    while (n) {
      s = ans % 10;
      ans /= 10;
      n--;
    }
    printf("%d\n", s);
  }
  return 0;
}
