#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long solve2(long long a) {
  if (a == 0) return 0;
  long long res = 0, t = a, x = 9, y = 1, len = 0;
  while (a) {
    len++;
    x = x * 10 + 9;
    y *= 10;
    a /= 10;
  }
  x /= 10;
  y /= 10;
  res += (t - y + 1) * len;
  len--;
  x /= 10;
  y /= 10;
  while (len) {
    res += (x - y + 1) * len;
    len--;
    x /= 10;
    y /= 10;
  }
  return res;
}
long long solve(long long a) {
  if (a == 0) return 0;
  long long r = solve2(a);
  long long res = 0, t = a, x = 9, y = 1, len = 0;
  while (a) {
    len++;
    x = x * 10 + 9;
    y *= 10;
    a /= 10;
  }
  x /= 10;
  y /= 10;
  long long l = solve2(y);
  res += (l + r) * (t - y + 1) / 2;
  len--;
  x /= 10;
  y /= 10;
  while (len) {
    l = solve2(y), r = solve2(x);
    res += (l + r) * (x - y + 1) / 2;
    len--;
    x /= 10;
    y /= 10;
  }
  return res;
}
long long check(long long a, long long b) {
  long long res = solve2(a);
  if (res <= b) return true;
  return false;
}
long long f[N];
int main() {
  int Q;
  f[0] = 0;
  scanf("%d", &Q);
  while (Q--) {
    long long n, l = 1, r = 2e9 + 5;
    scanf("%lld", &n);
    long long res = 1;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (solve(mid) <= n) {
        res = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    long long m = n - solve(res);
    if (m == 0) {
      printf("%d\n", res % 10);
      continue;
    }
    l = 1, r = res + 1;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (check(mid, m)) {
        res = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    long long j = solve2(res);
    if (j == m)
      res %= 10;
    else {
      long long k = res + 1;
      j = m - j;
      vector<int> vec;
      while (k) {
        vec.push_back(k % 10);
        k /= 10;
      }
      res = vec[vec.size() - j];
    }
    printf("%lld\n", res % 10);
  }
}
