#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <typename T>
T GCD(T a, T b) {
  long long t;
  while (a) {
    t = a;
    a = b % a;
    b = t;
  }
  return b;
}
template <typename T>
string toString(T a) {
  return to_string(a);
}
template <typename T>
void toInt(string s, T& x) {
  stringstream str(s);
  str >> x;
}
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline int mul(int x, int y) { return (x * 1ll * y) % mod; }
inline int powr(int a, long long b) {
  int x = 1 % mod;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return powr(a, mod - 2); }
long long get(long long n) { return n * (n + 1) / 2; }
long long check(long long n) {
  long long l = log(n) / log(10);
  long long ans = 0, cur = 10, prev = 1;
  for (int i = 1; i <= l; i++) {
    long long x = cur - prev;
    long long y = i * get(cur - prev);
    ans += x * i * (n - cur + 1);
    ans += y;
    prev = cur;
    cur *= 10;
  }
  l++;
  ans += l * get(n - prev + 1);
  return ans;
}
long long get2(long long l) {
  long long n = powl(10, l) - 1;
  long long ans = 0, cur = 10, prev = 1;
  for (int i = 1; i <= l; i++) {
    long long x = cur - prev;
    ans += x * i;
    prev = cur;
    cur *= 10;
  }
  return ans;
}
long long get1(long long v, long long n) {
  long long d = log(v) / log(10);
  long long low = 0, high = d + 1, mid, x = 0;
  while (low <= high) {
    mid = low + (high - low) / 2;
    if (get2(mid) >= n) {
      x = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  n -= get2(x - 1);
  long long a = powl(10, x - 1) - 1;
  d = n / x;
  long long r = n % x;
  long long num = a + d + (r > 0);
  r = (r - 1 + x) % x;
  string str = to_string(num);
  return (str[r] - '0');
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test;
  cin >> test;
  while (test--) {
    long long n;
    cin >> n;
    long long low = 1, high = 1e9, mid, v = 0;
    while (low <= high) {
      mid = low + (high - low) / 2;
      if (check(mid) >= n) {
        v = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
    n -= check(v - 1);
    long long ans = get1(v, n);
    cout << ans << '\n';
  }
  return 0;
}
