#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 200001;
int q;
long long k;
void Solve() {
  long long i = 1, b = 1;
  while (k > i * b * 9) {
    k -= i * b * 9;
    i++;
    b *= 10;
  }
  long long t = (k - 1) / i;
  b += t;
  k -= t * i;
  k = i - k;
  for (; k > 0; k--) {
    b /= 10;
  }
  cout << b % 10 << endl;
}
void Search(long long st, long long i, long long n) {
  long long l = 1, r = n, m, ans = 0;
  while (l <= r) {
    m = (l + r) >> 1;
    if ((st * 2 + i + i * m) * m / 2 < k) {
      ans = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  k -= (st * 2 + i + i * ans) * ans / 2;
}
int main() {
  cin >> q;
  while (q-- > 0) {
    cin >> k;
    long long st = 0, l = 9;
    for (long long i = 1;; i++) {
      long long v = (st * 2 + i + l * i) * l / 2;
      if (k <= v) {
        Search(st, i, l);
        Solve();
        break;
      }
      k -= v;
      st += l * i;
      l *= 10;
    }
  }
  return 0;
}
