#include <bits/stdc++.h>
using namespace std;
long long qu;
long long num(long long x) {
  long long cnt = 0, cpy = x;
  while (cpy) cnt++, cpy /= 10;
  long long res = 0, now = 1;
  for (long long i = 1; i < cnt; i++)
    res += i * ((x - now + 1) + (x - (now * 10 - 1) + 1)) * (now * 9) / 2,
        now *= 10;
  return res + cnt * ((x - now + 1) + 1) * (x - now + 1) / 2;
}
long long num0(long long x) {
  long long cnt = 0, cpy = x;
  while (cpy) cnt++, cpy /= 10;
  long long res = 0, now = 1;
  for (long long i = 1; i < cnt; i++) res += i * (now * 9), now *= 10;
  return res + cnt * (x - now + 1);
}
signed main() {
  cin >> qu;
  while (qu--) {
    long long x;
    cin >> x;
    long long to = -1;
    for (long long i = 30; ~i; i--)
      if (num(to + (1ll << i)) < x) to += 1ll << i;
    x -= num(to);
    long long ans = 0;
    for (long long i = 30; ~i; i--)
      if (num0(ans + (1ll << i)) < x) ans += 1ll << i;
    x -= num0(ans);
    vector<long long> dig;
    ans++;
    while (ans) dig.push_back(ans % 10), ans /= 10;
    reverse(dig.begin(), dig.end());
    cout << dig[x - 1] << "\n";
  }
  return 0;
}
