#include <bits/stdc++.h>
using namespace std;
long long tenp[20];
void calc() {
  tenp[0] = 1;
  for (int i = 1; i <= 18; i++) tenp[i] = (long long)10 * tenp[i - 1];
}
long long SUM(long long n) {
  if (n & 1) return n * ((n + 1) >> 1);
  return (n >> 1) * (n + 1);
}
long long LG(long long n) {
  if (n == 0) return 1;
  long long x = 0;
  while (n) {
    n /= (long long)10;
    x++;
  }
  return x;
}
long long P(long long n) {
  if (n == 0) return 0;
  long long d = LG(n), s = 0;
  for (long long i = 1; i <= d; i++) {
    long long x = tenp[i] - 1;
    long long y = tenp[i - 1];
    if (n <= x) return s + SUM(n - y + 1) * i;
    s += SUM(x - y + 1) * i + (n - x) * i * (long long)9 * tenp[i - 1];
  }
  return s;
}
long long G(long long x) {
  if (x == 0) return 0;
  return x * (long long)9 * tenp[x - 1];
}
char D(long long n, int x) {
  char s[20];
  sprintf(s, "%lld", n);
  return s[x - 1];
}
long long search(long long l, long long r, long long k) {
  if (P(l) >= k) return l;
  if (r - l < 5) {
    for (long long i = l; i < r; i++) {
      if (P(i) < k && P(i + 1) >= k) return i + 1;
    }
    return r;
  }
  long long m = (l + r) >> 1;
  if (P(m) < k) {
    if (P(m + 1) >= k) return m + 1;
    return search(m + 2, r, k);
  }
  return search(l, m, k);
}
int main() {
  calc();
  int q;
  cin >> q;
  while (q--) {
    long long k, x = 0;
    cin >> k;
    long long p = search(1, 500000000, k);
    k -= P(p - 1);
    x = 0;
    for (long long i = 1; i < 18; i++) {
      if (x + G(i) >= k || LLONG_MAX - G(i) < x) {
        k -= x;
        x = i;
        break;
      }
      x += G(i);
    }
    long long y = k % x;
    long long n = tenp[x - 1] + k / x + (y > 0) - 1;
    long long z = y ? y : x;
    cout << D(n, z) << endl;
  }
  return 0;
}
