#include <bits/stdc++.h>
using namespace std;
long long check(long long mid, int tag) {
  long long ans = 0;
  for (long long i = 1; i <= mid; i *= 10) {
    if (tag)
      ans = ans + (mid - i + 1) * (mid - i + 2) / 2;
    else
      ans += (mid - i + 1);
  }
  return ans;
}
long long k;
long long search(long long l, long long r, int tag) {
  while (l < r) {
    long long mid = (l + r + 1) / 2;
    if (check(mid, tag) < k)
      l = mid;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  int m;
  cin >> m;
  while (m--) {
    cin >> k;
    long long x = search(0, 2e9, 1);
    k -= check(x, 1);
    x = search(0, x, 0);
    k -= check(x, 0);
    cout << to_string(x + 1)[k - 1] << endl;
  }
  return 0;
}
