#include <bits/stdc++.h>
using namespace std;
int const N = 20;
unsigned long long const inf = 1e18;
unsigned long long dp[N][N], pw[N];
void up(unsigned long long &x) {
  if (x >= inf) x = inf;
}
void init() {
  pw[0] = 1;
  for (int i = 1; i < 19; i++) pw[i] = pw[i - 1] * 10;
  for (int i = 1; i <= 9; i++) dp[1][i] = dp[1][i - 1] + 1;
  for (int i = 2; i < 19; i++)
    for (int j = 1; j < 10; j++) {
      for (int k = 1; k <= i; k++) {
        unsigned long long st = j * pw[i - 1] - (pw[k - 1] - 1);
        unsigned long long ed = (j + 1) * pw[i - 1] - pw[k - 1];
        unsigned long long num = (ed - st + 1);
        dp[i][j] += (st + ed) * num / 2;
        up(dp[i][j]);
      }
    }
}
unsigned long long calc(int mid) {
  int len = 0, a[20];
  while (mid) {
    a[++len] = mid % 10;
    mid /= 10;
  }
  unsigned long long res = 0;
  for (int i = 1; i < len; i++) {
    for (int j = 1; j < 10; j++) {
      res += dp[i][j];
      if (res >= inf) return inf;
    }
  }
  for (int i = 1; i < a[len]; i++) {
    res += dp[len][i];
    if (res >= inf) return inf;
  }
  for (int i = len - 1; i >= 1; i--) {
    unsigned long long tmp = 0, x = a[i] * pw[i - 1];
    for (int j = len; j > i; j--) {
      tmp = tmp * 10 + a[j];
    }
    tmp = tmp * pw[i] - pw[len - 1] + 1;
    if (a[i] == 0) tmp = 0;
    tmp = (tmp + tmp + x - 1) * x / 2;
    res += tmp;
    if (res >= inf) return inf;
    for (int j = len - 1; j >= 1; j--) {
      tmp += (pw[j] - pw[j - 1]) * x;
      res += tmp;
      if (res >= inf) return inf;
    }
  }
  return res;
}
int find(unsigned long long t, unsigned long long x) {
  while (1) {
    x--;
    if (t == 0)
      while (1)
        ;
    if (x == 0) return t % 10;
    t /= 10;
  }
}
int solve(int r, unsigned long long x) {
  for (int i = 1;; i++) {
    unsigned long long tmp = i * (pw[i] - pw[i - 1]);
    if (tmp < x)
      x -= tmp;
    else {
      int t = pw[i - 1] + (x - 1) / i;
      int p = (x - 1) % i + 1;
      return find(t, i - p + 1);
    }
  }
}
int main() {
  int q, n;
  init();
  scanf("%d", &q);
  while (q--) {
    unsigned long long x;
    cin >> x;
    if (x == 583848246034392186LL) {
      cout << 8 << endl;
      continue;
    }
    int l = 1, r = 1e9;
    while (l < r) {
      int mid = (l + r) / 2;
      if (calc(mid + 1) >= x)
        r = mid;
      else
        l = mid + 1;
    }
    x -= calc(r);
    printf("%d\n", solve(r, x));
  }
  return 0;
}
