#include <bits/stdc++.h>
using namespace std;
long long int cal2(long long int now) {
  if (now == 0) return 0;
  long long int f = 1;
  for (long long int e = 1; e <= 9; e++) {
    if (now >= f && now < f * 10) {
      long long int ans = 0, pp = 1;
      for (long long int p = 1; p < e; p++) {
        long long int rr = (pp * 10) - 1;
        long long int ll = pp;
        ans += ((p * (rr - ll + 1) * (now + 1)) -
                (p * ((rr * (rr + 1) / 2) - ((ll - 1) * (ll) / 2))));
        pp *= 10;
      }
      ans += ((e * (now - pp + 1) * (now + 1)) -
              (e * (((now * (now + 1)) / 2) - (pp * (pp - 1) / 2))));
      return ans;
    }
    f *= 10;
  }
}
long long int cal(long long int now, long long int k) {
  long long int f = cal2(now - 1);
  long long int s = cal2(now);
  if (k > f && k <= s) return f;
  if (k <= f) return -1;
  return -2;
}
long long int cal3(long long int dist) {
  long long int p = 10, nu = 10, lnu = 0;
  for (long long int e = 1; e <= 9; e++) {
    if (dist < nu) {
      long long int ddist = dist - lnu;
      long long int f = (ddist / e);
      long long int r = (ddist % e);
      long long int now = (p / 10);
      if (now == 1) now = 0;
      long long int nnow = now + f;
      vector<int> k;
      while (nnow != 0) {
        k.push_back(nnow % 10);
        nnow /= 10;
      }
      reverse(k.begin(), k.end());
      return k[r];
    } else {
      lnu = nu;
      nu += (p * 9) * (e + 1);
      p *= 10;
    }
  }
}
int main(void) {
  int q;
  scanf("%d", &q);
  while (q--) {
    long long int k;
    scanf("%lld", &k);
    long long int l = 1, r = 2e9, mid;
    while (l <= r) {
      mid = (l + r) / 2;
      long long int now = cal(mid, k);
      if (now >= 0) {
        long long int dist = k - now;
        printf("%lld\n", cal3(dist));
        break;
      } else if (now == -2) {
        l = mid + 1;
      } else if (now == -1) {
        r = mid - 1;
      }
    }
  }
}
