#include <bits/stdc++.h>
using namespace std;
vector<long long> pow_10(10, 1);
long long sume(long long n) {
  return n % 2 ? ((n + 1) / 2) * n : (n / 2) * (n + 1);
}
long long calc_sum_n(long long n) {
  long long sum = 0;
  long long j = n, i = 0;
  while (j) {
    sum += sume(n - pow_10[i] + 1);
    j /= 10, i++;
  }
  return sum;
}
long long calc_v_n(long long n) {
  long long v = 0;
  long long j = n, i = 0;
  while (j) {
    v += n - pow_10[i] + 1;
    j /= 10, i++;
  }
  return v;
}
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= 9; i++) pow_10[i] = pow_10[i - 1] * 10;
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long l = 1, r = 5 * 1e8;
    long long mid, ans, j, k;
    vector<int> temp;
    while (r - l > 1) {
      mid = l + r >> 1;
      if (calc_sum_n(mid) == n) {
        cout << mid % 10;
        goto done;
      } else if (calc_sum_n(mid) < n)
        l = mid;
      else
        r = mid;
    }
    ans = calc_sum_n(r) <= n ? r : r - 1;
    if (calc_sum_n(ans) == n) {
      cout << ans % 10;
      goto done;
    }
    n -= calc_sum_n(ans);
    l = 1, r = ans + 1;
    while (r - l > 1) {
      mid = l + r >> 1;
      if (calc_v_n(mid) == n) {
        cout << mid % 10;
        goto done;
      } else if (calc_v_n(mid) < n)
        l = mid;
      else
        r = mid;
    }
    ans = calc_v_n(r) <= n ? r : r - 1;
    if (calc_v_n(ans) == n) {
      cout << ans % 10;
      goto done;
    }
    n -= calc_v_n(ans);
    j = n, k = ans + 1;
    while (k) temp.push_back(k % 10), k /= 10;
    reverse(temp.begin(), temp.end());
    cout << temp[j - 1];
  done:
    cout << endl;
  }
}
