#include <bits/stdc++.h>
using namespace std;
inline long long que1(long long n) {
  long long y = 0, ans = 0;
  while (n > y) {
    ans += n - y;
    y = 10 * y + 9;
  }
  return ans;
}
inline long long tell1(long long n) {
  long long s = 1, e = 1000000005;
  while (s < e) {
    long long m = (s + e) / 2;
    long long dgt = que1(m);
    if (dgt <= n - 1)
      s = m + 1;
    else
      e = m;
  }
  return s;
}
inline long long sum(long long n) { return (n * (n + 1)) / 2; }
inline long long que2(long long n) {
  long long ans = 0, x = 1, num = 9;
  while (n >= num) {
    ans += x * (sum(n) - sum(n - num));
    n -= num;
    x++;
    num *= 10;
  }
  ans += x * sum(n);
  return ans;
}
inline long long tell2(long long n) {
  long long s = 1, e = 1000000005;
  while (s < e) {
    long long m = (s + e) / 2;
    long long dgt = que2(m);
    if (dgt <= n - 1)
      s = m + 1;
    else
      e = m;
  }
  return s - 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    if (n == 1 || n == 2) {
      cout << 1 << endl;
      continue;
    }
    long long a = tell2(n);
    n -= que2(a);
    long long b = tell1(n);
    n -= que1(b - 1);
    string ans = to_string(b);
    cout << ans[n - 1] << endl;
  }
}
