#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
inline long long countDigits(long long n) {
  long long cnt = 0;
  while (n > 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}
inline long long getPos(long long a) {
  long long l = countDigits(a);
  long long res = 0;
  for (long long i = 0; i < l - 1; i++) res = res * 10 + 9;
  long long offset = 0;
  long long prev = a, curr = res;
  long long ans = 0;
  while (prev > 0) {
    long long d = prev - curr;
    ans += (d * (d + 1) / 2 + offset * d) * l;
    offset += d;
    l--;
    prev = curr;
    curr /= 10;
  }
  return ans;
}
inline long long getPosv2(long long a) {
  long long l = countDigits(a);
  long long res = 0;
  for (long long i = 0; i < l - 1; i++) res = res * 10 + 9;
  long long prev = a, curr = res;
  long long ans = 0;
  while (prev > 0) {
    ans += (prev - curr) * l;
    l--;
    prev = curr;
    curr /= 10;
  }
  return ans;
}
long long k;
inline void solve() {}
signed main() {
  long long T = read();
  while (T--) {
    long long k = read();
    long long l = 1, r = 1e9;
    while (l < r) {
      long long mid = (l + r + 1) >> 1;
      long long val = getPos(mid);
      if (val > k)
        r = mid - 1;
      else
        l = mid;
    }
    long long d = k - getPos(l);
    if (d == 0) {
      cout << l % 10 << endl;
      continue;
    }
    r = l + 1, l = 1;
    while (l < r) {
      long long mid = l + r >> 1;
      long long val = getPosv2(mid);
      if (val < d)
        l = mid + 1;
      else
        r = mid;
    }
    long long z = getPosv2(l) - d;
    long long ans = 0;
    while (z >= 0) {
      ans = l % 10;
      l /= 10;
      z--;
    }
    cout << ans << endl;
  }
  return 0;
}
