#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void print_digit(LL K) {
  for (LL p = 1, d = 1;; p *= 10, d += 1) {
    if (K <= 9 * p * d) {
      LL i = (K - 1) / d;
      K -= i * d;
      LL n = p + i;
      while (K > 1) {
        n -= (n / p) * p;
        K -= 1;
        p /= 10;
      }
      cout << n / p << endl;
      return;
    }
    K -= 9 * p * d;
  }
}
void solve_problem() {
  LL Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    LL K;
    cin >> K;
    LL l = 0;
    for (LL p = 1, d = 1;; p *= 10, d += 1) {
      LL m = 9 * p;
      LL s = ((m * m + m) / 2) * d + m * l;
      if (s < K) {
        K -= s;
        l += m * d;
        continue;
      }
      LL x1 = 1, x2 = m;
      while (x1 < x2) {
        LL y = x1 + (x2 - x1) / 2;
        if (K <= (y * (y + 1) / 2) * d + y * l) {
          x2 = y;
        } else {
          x1 = y + 1;
        }
      }
      LL x = x1 - 1;
      K -= ((x * (x + 1) / 2) * d + x * l);
      print_digit(K);
      break;
    }
  }
}
int main() { solve_problem(); }
