#include <bits/stdc++.h>
using namespace std;
unsigned long long len[20];
unsigned long long f[20];
int a[20];
void jzk(unsigned long long l, unsigned long long n) {
  int cnt = 0;
  while (l) {
    a[++cnt] = l % 10;
    l /= 10;
  }
  reverse(a + 1, a + cnt + 1);
  printf("%d\n", a[n]);
}
unsigned long long power(unsigned long long a, int b) {
  unsigned long long res = 1;
  while (b--) res *= a;
  return res;
}
unsigned long long calc(unsigned long long k, unsigned long long pos) {
  k -= power(10, pos - 1) - 1;
  unsigned long long ans =
      f[pos - 1] + pos * ((k * (k + 1)) / 2) + len[pos - 1] * k;
  return ans;
}
bool check(unsigned long long k, unsigned long long n, unsigned long long pos) {
  unsigned long long ans = calc(k, pos);
  if (ans >= n) return true;
  return false;
}
unsigned long long calc1(unsigned long long k, unsigned long long wei) {
  k -= power(10, wei - 1) - 1;
  unsigned long long ans = len[wei - 1] + k * wei;
  return ans;
}
bool check1(unsigned long long k, unsigned long long wei,
            unsigned long long n) {
  unsigned long long ans = calc1(k, wei);
  if (ans >= n) return true;
  return false;
}
void print(unsigned long long n, unsigned long long end) {
  int pos = 1;
  for (int i = 9; i >= 1; i--)
    if (n > len[i]) {
      pos = i + 1;
      break;
    }
  unsigned long long l = 1;
  unsigned long long r = end;
  while (l + 1 < r) {
    unsigned long long k = (l + r) / 2;
    if (check1(k, pos, n))
      r = k;
    else
      l = k;
  }
  if (check1(l, pos, n) == false) l = r;
  unsigned long long ans = calc1(l - 1, pos);
  n -= ans;
  jzk(l, n);
}
int main() {
  len[1] = 9;
  for (int i = 2; i < 10; i++) len[i] = len[i - 1] + 9 * power(10, i - 1) * i;
  f[1] = 45;
  for (int i = 2; i < 10; i++) {
    unsigned long long t = 9 * power(10, i - 1);
    f[i] = f[i - 1] + i * ((t * (t + 1)) / 2) + len[i - 1] * t;
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    unsigned long long n;
    scanf("%llu", &n);
    unsigned long long pos = 1;
    for (int i = 9; i >= 1; i--) {
      if (n > f[i]) {
        pos = i + 1;
        break;
      }
    }
    unsigned long long l = power(10, pos - 1);
    unsigned long long r = power(10, pos) - 1;
    while (l + 1 < r) {
      unsigned long long k = (l + r) / 2;
      if (check(k, n, pos))
        r = k;
      else
        l = k;
    }
    if (check(l, n, pos) == false) l = r;
    unsigned long long ans = calc(l - 1, pos);
    n -= ans;
    print(n, l);
  }
}
