#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long M = 3e5 + 5;
const long long mod = 1e9 + 7;
const long long m1 = 1e9 + 7;
const long long m2 = 1e9 + 9;
const long long p1 = 402653189;
const long long p2 = 1610612741;
const int LN = 32;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long power(long long _a, long long _b) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long dx[4] = {-1, 1, 0, 0};
long long dy[4] = {0, 0, 1, -1};
long long pw[LN], fact[N], invfact[N];
void pre() {
  fact[0] = 1;
  for (int i = 0; i < LN; i++) pw[i] = power(2, i);
  for (int i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % mod;
  for (int i = 0; i < N; i++) invfact[i] = powermodm(fact[i], mod - 2, mod);
}
long long sum[100], dp[100];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i, j;
  long long curr = 9;
  for (i = 1;; i++) {
    dp[i] = dp[i - 1] + curr * i;
    sum[i] = sum[i - 1] + curr * dp[i - 1] + ((curr * (curr + 1)) / 2) * i;
    curr *= 10;
    if (sum[i] >= 1e18) break;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long digits = 0;
    for (i = 0; i < 9; i++) {
      if (sum[i] < k) digits = i;
    }
    k -= sum[digits];
    digits++;
    long long val = power(10, digits - 1);
    long long l = power(10, digits - 1), r = power(10, digits) - 1, mi = r;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long tmp = mid - val + 1;
      long long tot = tmp * dp[digits - 1] + ((tmp * (tmp + 1)) / 2) * digits;
      if (tot >= k) {
        r = mid - 1;
        mi = min(mi, mid);
      } else
        l = mid + 1;
    }
    long long tmp = mi - val;
    long long tot = tmp * dp[digits - 1] + ((tmp * (tmp + 1)) / 2) * digits;
    k -= tot;
    curr = 9;
    long long dig = 1;
    for (i = 1; i <= digits; i++) {
      if (k > curr * i) {
        k -= curr * i;
        curr *= 10;
      } else {
        dig = i;
        break;
      }
    }
    long long num = power(10, dig - 1) + (k - 1) / dig;
    long long idx = (k - 1) % dig;
    vector<long long> decimal;
    while (num) {
      decimal.push_back(num % 10);
      num /= 10;
    }
    reverse(decimal.begin(), decimal.end());
    cout << decimal[idx] << "\n";
  }
  return 0;
}
