#include <bits/stdc++.h>
using namespace std;
void Work() {
  long long n;
  scanf("%lld", &n);
  long long LastLen = 0, Len, Count;
  for (Len = 1;; ++Len) {
    Count = 9;
    for (long long i = 1; i < Len; ++i) Count = Count * 10;
    long long Sum = (LastLen + Len + LastLen + Count * Len) * Count / 2;
    if (n <= Sum) break;
    n -= Sum;
    LastLen += Count * Len;
  }
  long long Left = 1, Right = Count, Mid, Ans;
  while (Left <= Right) {
    Mid = (Left + Right) >> 1;
    long long Sum = (LastLen + Len + LastLen + Mid * Len) * Mid / 2;
    if (Sum >= n) {
      Ans = Mid;
      Right = Mid - 1;
    } else
      Left = Mid + 1;
  }
  --Ans;
  n -= (LastLen + Len + LastLen + Ans * Len) * Ans / 2;
  ++Ans;
  for (Len = 1;; ++Len) {
    Count = 9;
    for (long long i = 1; i < Len; ++i) Count = Count * 10;
    long long Sum = Count * Len;
    if (Sum >= n) break;
    n -= Sum;
  }
  long long Num = (n + Len - 1) / Len;
  n = n - (Num - 1) * Len;
  long long T = 1;
  for (long long i = 1; i < Len; ++i) T = T * 10;
  Num = T + Num - 1;
  T = Len - n + 1;
  for (long long i = 1; i < T; ++i) Num = Num / 10;
  printf("%lld\n", Num % 10);
  return;
}
int main() {
  long long Query;
  scanf("%lld", &Query);
  for (long long i = 1; i <= Query; ++i) Work();
  return 0;
}
