#include <bits/stdc++.h>
using namespace std;
long long dig(long long x) {
  long long k = 0;
  while (x != 0) x /= 10, k++;
  return k;
}
long long C1(long long x, long long y) {
  x = (x * (x + 1)) / 2;
  y = (y * (y + 1)) / 2;
  return (x - y);
}
long long L1(long long x, long long c) {
  long long i, d = 0, r, l;
  for (i = 1;; i *= 10) {
    if (x < (i * 10)) {
      l = (x - i + 1);
      d += dig(i) * C1(c, c - l);
      return d;
    }
    l = (i * 10) - i;
    d += dig(i) * C1(c, c - l);
    c -= l;
  }
}
long long L2(long long x) {
  long long i, d = 0;
  for (i = 1;; i *= 10) {
    if (x < (i * 10)) {
      d += (x - i + 1) * dig(i);
      return d;
    }
    d += ((i * 10) - i) * dig(i);
  }
}
void print(long long x, long long d) {
  string s;
  while (x != 0) s += (char)((x % 10) + 48), x /= 10;
  reverse(s.begin(), s.end());
  cout << s[d - 1] << "\n";
}
void ANS(long long n, long long d) {
  long long l, r, m, x, y;
  l = 1, r = n;
  while (l <= r) {
    m = (l + r) / 2;
    x = L2(m - 1);
    y = L2(m);
    if (d > x && d <= y) {
      print(m, d - x);
      break;
    }
    if (y < d)
      l = m + 1;
    else
      r = m - 1;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, n, l, r, m, x, y;
  cin >> t;
  while (t--) {
    cin >> n;
    l = 1, r = 2e9;
    while (l <= r) {
      m = (l + r) / 2;
      x = L1(m - 1, m - 1);
      y = L1(m, m);
      if (n > x && n <= y) {
        ANS(m, n - x);
        break;
      }
      if (y < n)
        l = m + 1;
      else
        r = m - 1;
    }
  }
  return 0;
}
