#include <bits/stdc++.h>
using namespace std;
unsigned long long c[20];
unsigned long long sum[20];
unsigned long long r[20];
unsigned long long solve(unsigned long long n) {
  for (int k = 1; k <= 11; k++) {
    unsigned long long x = (sum[k] + k + sum[k - 1]) * c[k] / 2;
    if (x < n) {
      n -= x;
    } else {
      unsigned long long l = 1, r = c[k], ans = -1;
      while (l <= r) {
        unsigned long long m = (l + r) >> 1;
        unsigned long long res = (sum[k - 1] * 2 + (m + 1) * k) * m / 2;
        if (res >= n) {
          r = m - 1, ans = m;
        } else
          l = m + 1;
      }
      unsigned long long res1 = sum[k - 1] + k;
      unsigned long long res2 = sum[k - 1] + (ans - 1) * k;
      unsigned long long res = (res1 + res2) * (ans - 1) / 2;
      n -= res;
      return n;
    }
  }
  return n;
}
int main() {
  ios::sync_with_stdio(false);
  c[1] = 9;
  sum[1] = 9;
  r[1] = 9;
  for (int i = 2; i <= 18; i++) {
    c[i] = c[i - 1] * 10;
    sum[i] = sum[i - 1] + c[i] * i;
  }
  int t;
  cin >> t;
  while (t--) {
    unsigned long long n;
    cin >> n;
    int x = 1;
    n = solve(n);
    while (sum[x] < n) x++;
    unsigned long long y = n - sum[x - 1];
    unsigned long long a = y / x;
    unsigned long long b = y % x;
    auto f = [](unsigned long long x, int bit) {
      vector<int> v;
      while (x) {
        v.push_back(x % 10);
        x /= 10;
      }
      reverse(v.begin(), v.end());
      return v[bit - 1];
    };
    long long num = 1;
    for (int i = 1; i < x; i++) num *= 10;
    if (b == 0)
      cout << f(num + a - 1, x) << endl;
    else
      cout << f(num + a, b) << endl;
  }
  return 0;
}
