#include <bits/stdc++.h>
using namespace std;
long long sum(long long l, long long r) { return (l + r) * (r - l + 1) / 2; }
long long calc1(long long num) {
  long long ret = 0, mul = 1, cur = 1;
  while (num >= mul) {
    long long L = mul, R = min(num, mul * 10 - 1);
    ret += cur++ * (num * (R - L + 1) - sum(L - 1, R - 1));
    mul *= 10;
  }
  return ret;
}
long long calc2(long long num) {
  long long ret = 0, mul = 1;
  while (num >= mul) {
    ret += num - mul + 1;
    mul *= 10;
  }
  return ret;
}
int solve(long long k) {
  long long l = 1, r = 1e9;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (calc1(mid) >= k) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  k -= calc1(r - 1), l = 0;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (calc2(mid) >= k) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  k -= calc2(r - 1);
  return (to_string(r)[k - 1] - '0');
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long k;
    scanf("%lld", &k);
    printf("%d\n", solve(k));
  }
  return 0;
}
