#include <bits/stdc++.h>
using namespace std;
long long int sumTo(long long int k) { return k * (k + 1) / 2; }
long long int value(int a) {
  long long int sum = 9;
  for (int i = (1) - ((1) > (a)); i != (a) - ((1) > (a));
       i += 2 * ((1) < (a)) - 1)
    sum *= 10;
  return sum;
}
long long int sum(long long int n) {
  int now = 1, tmp = 1;
  long long int ans = 0;
  while (now <= n) {
    ans += tmp * sumTo(min(n - now + 1, value(tmp)));
    ans += max(n - now * 10 + 1, 0ll) * value(tmp) * tmp;
    now *= 10;
    tmp++;
  }
  return ans;
}
int find(long long int n) {
  long long int a = 0, now = 9, tmp = 1;
  while (true) {
    if (n >= now * tmp) {
      n -= now * tmp;
      a += now;
    } else {
      int k = n / tmp;
      a += k;
      n %= tmp;
      break;
    }
    now *= 10;
    tmp++;
  }
  if (n == 0) return a % 10;
  a++;
  for (int i = (0) - ((0) > (tmp - n)); i != (tmp - n) - ((0) > (tmp - n));
       i += 2 * ((0) < (tmp - n)) - 1) {
    a /= 10;
  }
  return a % 10;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int l = 0, r = 490000000, m;
    while (r - l != 1) {
      m = (l + r) >> 1;
      if (sum(m) > n)
        r = m;
      else
        l = m;
    }
    n -= sum(l);
    if (n == 0)
      cout << l % 10 << endl;
    else
      cout << find(n) << endl;
  }
}
