#include <bits/stdc++.h>
using namespace std;
long long int p[12];
int dig(int x) {
  int ct = 0;
  while (x > 0) {
    ++ct;
    x /= 10;
  }
  return ct;
}
long long int cal(long long int mi) {
  if (mi == 0) return 0;
  long long int pres = 0;
  long long int tot = 0;
  int d = dig(mi);
  for (long long i = 1; i < d; i++) {
    long long int x = p[i] - p[i - 1];
    tot += x * pres + i * x * (x + 1) / 2;
    pres += x * i;
  }
  long long int x = mi - p[d - 1] + 1;
  tot += x * pres + d * x * (x + 1) / 2;
  return tot;
}
long long int cal2(long long int mi) {
  if (mi == 0) return 0;
  long long int tot = 0;
  int d = dig(mi);
  for (long long i = 1; i < d; i++) {
    long long int x = p[i] - p[i - 1];
    tot += i * x;
  }
  long long int x = mi - p[d - 1] + 1;
  tot += d * x;
  return tot;
}
void solve() {
  long long int n;
  cin >> n;
  long long int lo = 1, hi = 1e9, mi;
  while (lo < hi) {
    mi = (lo + hi) >> 1;
    long long int tot = cal(mi);
    if (tot < n)
      lo = mi + 1;
    else
      hi = mi;
  }
  n -= cal(hi - 1);
  long long int b = hi;
  lo = 1;
  while (lo < hi) {
    mi = (lo + hi) >> 1;
    long long int temp = cal2(mi);
    if (temp < n)
      lo = mi + 1;
    else
      hi = mi;
  }
  n -= cal2(hi - 1);
  long long int x = dig(hi);
  for (long long i = 0; i < x - n; i++) hi /= 10;
  hi %= 10;
  cout << hi << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  p[0] = 1;
  for (long long i = 1; i < 11; i++) p[i] = p[i - 1] * 10;
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
}
