#include <bits/stdc++.h>
using namespace std;
long long solve(long long x) {
  long long ret = 0;
  for (long long c = 1; c <= x; c *= 10) {
    ret += (x - c + 1) * (x - c + 2) / 2;
  }
  return ret;
}
long long solve2(long long x) {
  long long ret = 0;
  for (long long c = 1; c <= x; c *= 10) {
    ret += x - c + 1;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int Q;
  for (cin >> Q; Q--;) {
    long long k;
    int s = 0, e = 1e9;
    cin >> k;
    while (s <= e) {
      int m = (s + e) >> 1;
      if (solve(m) < k)
        s = m + 1;
      else
        e = m - 1;
    }
    k -= solve(e);
    e = s;
    s = 0;
    while (s <= e) {
      int m = (s + e) >> 1;
      if (solve2(m) < k)
        s = m + 1;
      else
        e = m - 1;
    }
    k -= solve2(e);
    cout << to_string(s)[k - 1] << '\n';
  }
  return 0;
}
