#include <bits/stdc++.h>
using namespace std;
long long a[11111111];
long long b[11111111];
int len = 0;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
int counter(int x) {
  int res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
void printK(int x, int k) {
  int n = counter(x);
  n = n - k + 1;
  for (int i = 0; i < n - 1; i++) x /= 10;
  cout << x % 10 << '\n';
}
long long g(long long x) {
  long long res = 0;
  int len = 1;
  long long tmp = 9;
  while (x > tmp) {
    res += tmp * len;
    x -= tmp;
    tmp *= 10;
    len++;
  }
  res += x * len;
  return res;
}
long long f(long long x) {
  long long res = 0;
  long long tmp = 0;
  while (x >= 0) {
    res += (1 + x) * x / 2;
    if (tmp == 0)
      tmp = 9;
    else
      tmp = tmp * 10;
    x -= tmp;
  }
  return res;
}
int main() {
  long long q, k;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> k;
    long long m, l = 0, r = 2000000001;
    while (l < r - 1) {
      m = (l + r) >> 1;
      if (f(m) < k) {
        l = m;
      } else {
        r = m;
      }
    }
    k -= f(l);
    r = l + 2, l = 0;
    while (l < r - 1) {
      m = (l + r) >> 1;
      if (g(m) < k) {
        l = m;
      } else {
        r = m;
      }
    }
    k -= g(l);
    long long n = 0;
    long long L = l + 1;
    l++;
    while (L) {
      L /= 10;
      n++;
    }
    n = n - k + 1;
    for (int j = 0; j < n - 1; j++) l /= 10;
    cout << l % 10 << endl;
  }
  return 0;
}
