#include <bits/stdc++.h>
using namespace std;
unsigned long long arr9[10] = {0,     9,      90,      900,      9000,
                               90000, 900000, 9000000, 90000000, 900000000};
unsigned long long a[10] = {0, 45};
unsigned long long power(unsigned long long x, unsigned long long n) {
  unsigned long long y = 1;
  for (unsigned long long i = 1; i <= n; i++) {
    y *= x;
  }
  return y;
}
unsigned long long cnt_digs(unsigned long long x) {
  if (x == 0) {
    return 0;
  }
  int n = (int)log10(x) + 1;
  unsigned long long cnt = a[n - 1];
  unsigned long long p = x - power(10, n - 1) + 1;
  for (unsigned long long j = 1; j < n; j++) {
    cnt += j * arr9[j] * p;
  }
  cnt += (n + n * p) * p / 2;
  return cnt;
}
bool check(unsigned long long m, unsigned long long n) {
  return (n <= cnt_digs(m));
}
void print_ans(unsigned long long p) {
  int i = 1;
  while (arr9[i] * i <= p) {
    p -= i * arr9[i];
    i++;
  }
  if (i == 1) {
    cout << p << endl;
    return;
  }
  unsigned long long p_r = p % i;
  p = p / i;
  unsigned long long x = power(10, i - 1) + p - (p_r == 0);
  if (p_r == 0) {
    cout << x % 10 << endl;
    return;
  }
  cout << to_string(x)[p_r - 1] << endl;
}
int main() {
  unsigned long long x = 99;
  for (unsigned long long i = 2; i <= 9; i++) {
    a[i] = cnt_digs(x);
    x = x * 10 + 9;
  }
  unsigned long long q, n;
  cin >> q;
  while (q--) {
    cin >> n;
    int L = 1, R = 1000000000, m;
    while (L < R) {
      m = (L + R) / 2;
      if (check(m, n)) {
        R = m;
      } else {
        L = m + 1;
      }
    }
    print_ans(n - cnt_digs(L - 1));
  }
  return 0;
}
