#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T updmax(T& a, T b) {
  return a = max(a, b);
}
template <class T>
inline T updmin(T& a, T b) {
  return a = min(a, b);
}
const long long m = 1600000000;
long long getlen(long long x) {
  x++;
  long long len = 0;
  for (long long d = 1, a = 1, s = 1, e = 10;; d++, s *= 10, e *= 10) {
    updmin(e, x);
    long long k = e - s;
    len += k * a + (k * (k - 1)) / 2 * d;
    a += k * d + 1;
    if (x == e) return len;
  }
}
long long getlen2(long long x) {
  x++;
  long long len = 0;
  for (long long d = 1, s = 1, e = 10;; d++, s *= 10, e *= 10) {
    updmin(e, x);
    long long k = e - s;
    len += d * k;
    if (x == e) return len;
  }
}
int getval(long long x) {
  long long ok = m, ng = 0;
  while (abs(ok - ng) > 1) {
    long long mid = (ok + ng) / 2;
    bool flag = false;
    if (getlen2(mid) >= x) flag = true;
    if (flag)
      ok = mid;
    else
      ng = mid;
  }
  x -= getlen2(ng);
  return to_string(ok)[x - 1] - '0';
}
class Solution {
 public:
  void solve() {
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
      long long k;
      cin >> k;
      long long ok = m, ng = 0;
      while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        bool flag = false;
        if (k <= getlen(mid)) flag = true;
        if (flag)
          ok = mid;
        else
          ng = mid;
      }
      k -= getlen(ng);
      cout << getval(k) << "\n";
    }
    return;
  };
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Solution solution;
  solution.solve();
  return 0;
}
