#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LLINF = 1e18;
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
long long sum[11] = {0};
long long sumd[11] = {0};
long long D[11] = {1,       10,       100,       1000,       10000,      100000,
                   1000000, 10000000, 100000000, 1000000000, 10000000000};
long long maxx[11] = {0};
long long cal(long long id, long long d, long long f) {
  return id * f + (id - 1) * id * d / 2ll;
}
inline long long Find(long long x, int d, long long f) {
  long long l = 1, r = D[d] - D[d - 1], ret = 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (cal(mid, d, f) >= x) {
      ret = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ret;
}
inline int getdigit(int id, long long x) {
  long long tmp = x;
  int ret;
  for (int i = 1; i <= id; i++) {
    ret = x % 10;
    x /= 10;
  }
  return ret;
}
int main() {
  long long now = 0;
  for (int i = 1; i <= 9; i++) {
    long long len = D[i] - D[i - 1];
    maxx[i] = maxx[i - 1] + len * i;
    long long f = maxx[i - 1] + i;
    sum[i] = sum[i - 1] + cal(len, i, f);
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    for (int i = 1; i <= 9; i++) {
      if (sum[i] >= k) {
        long long rest = k - sum[i - 1];
        long long f = maxx[i - 1] + i;
        long long val = Find(rest, i, f);
        long long re = rest - cal(val - 1, i, f);
        val = D[i - 1] + val - 1;
        long long lsum = 0;
        for (int j = 1; j <= 9; j++) {
          long long nowsum = lsum + 1ll * j * (D[j] - D[j - 1]);
          if (nowsum >= re) {
            re -= lsum;
            long long del = re / j;
            del = D[j - 1] + del;
            long long res = re % j;
            if (res == 0) res = j, --del;
            cout << getdigit(j - res + 1, del) << endl;
            break;
          }
          lsum = nowsum;
        }
        break;
      }
    }
  }
}
