#include <bits/stdc++.h>
using namespace std;
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
const long long INF = 1e9;
const long long mod = (1e9) + 7;
const int maxn = (int)100;
const long double PI = acos(-1.0);
const long double eps = 0.000000001;
mt19937 rnd(time(0));
long long step[19];
long long lower(long long a_0, long long d, long long k) {
  long long l = 0, r = INF;
  while (r - l > 1) {
    long long m = r + l >> 1;
    long long a_m = a_0 + d * (m - 1);
    long long sum = (a_0 + a_m) * m / 2;
    (sum >= k ? r : l) = m;
  }
  return l;
}
void solve1(long long k) {
  for (long long i = 1; i < 19; ++i) {
    long long plus = i * (step[i] - step[i - 1]);
    if (plus == k) {
      cout << "9\n";
      return;
    }
    if (k > plus) {
      k -= plus;
      continue;
    }
    long long x = (k + i - 1) / i;
    k %= i;
    long long num = step[i - 1] + x - 1;
    string ans = to_string(num);
    if (!k) k = i;
    cout << ans[k - 1] << '\n';
    return;
  }
}
void solve() {
  long long k;
  cin >> k;
  long long a_0 = 1;
  for (long long i = 1; i < 19; ++i) {
    long long n = step[i] - step[i - 1];
    long long a_n = a_0 + i * (n - 1);
    long long sum = (a_0 + a_n) * n / 2ll;
    if (k == sum) {
      cout << "9\n";
      return;
    }
    if (k > sum) {
      k -= sum;
      a_0 = a_n + i + 1;
      continue;
    }
    long long x = lower(a_0, i, k);
    long long a_x = a_0 + i * (x - 1);
    k -= (a_0 + a_x) * x / 2;
    solve1(k);
    return;
  }
}
signed main() {
  GO();
  step[0] = 1;
  for (int i = 1; i < 19; ++i) step[i] = step[i - 1] * 10ll;
  int Q = 1;
  cin >> Q;
  while (Q--) {
    solve();
  }
}
