#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
void debug(T value, string name) {
  cout << name << " = " << value << '\n';
}
long long nctwo(long long r) {
  if (r % 2 == 0) {
    long long ret = r / 2;
    ret *= (r + 1);
    return ret;
  }
  long long ret = (r + 1) / 2;
  ret *= r;
  return ret;
}
long long block_sum(long long index) {
  long long pw = 1;
  long long prev_len = 0;
  long long last_len = 1;
  long long add;
  long long prev_block_size = 0;
  long long block_size;
  long long total = 0;
  for (long long len = 1;; ++len) {
    block_size = pw * 10LL - pw;
    last_len = len;
    if (block_size + prev_block_size >= index) break;
    add = prev_len * block_size + nctwo(block_size) * len;
    prev_len += block_size * len;
    pw *= 10LL;
    total += add;
    prev_block_size += block_size;
  }
  index -= prev_block_size;
  long long best = index;
  long long ret = prev_len * best + nctwo(best) * last_len;
  return ret + total;
}
void mIndex(long long k) {
  long long pw = 1;
  long long prev_len = 0;
  long long last_len = 0;
  long long new_len;
  for (long long len = 1;; ++len) {
    new_len = pw * 10 - pw;
    last_len = len;
    if (prev_len + new_len * len >= k) {
      break;
    }
    prev_len += new_len * len;
    pw *= 10;
  }
  k -= prev_len;
  long long left = 0, right = new_len;
  long long best = 0;
  while (left <= right) {
    long long mid = left + (right - left) / 2;
    if (mid * last_len < k) {
      best = mid;
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  k -= best * last_len;
  best += pw;
  cout << to_string(best)[k - 1] << '\n';
}
int main(int argv, char **argc) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  long long k;
  cin >> q;
  while (q--) {
    cin >> k;
    long long left = 0, right = 1e9, highest = 0;
    while (left <= right) {
      long long mid = left + (right - left) / 2;
      long long ret = block_sum(mid);
      if (ret < k) {
        highest = ret;
        left = mid + 1;
      } else {
        right = mid - 1;
      }
    }
    k -= highest;
    mIndex(k);
  }
}
