#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
int q;
long long pw[12];
long long getsum(long long x) {
  long long sum = 0LL;
  for (int i = 0;; ++i) {
    if (x - (pw[i] - 1) <= 0) return sum;
    long long v1 = x - (pw[i] - 1);
    long long v2 = max(0LL, x - (pw[i + 1] - 2));
    sum += (long long)(i + 1) * (v1 + v2) * (v1 - v2 + 1) / 2;
    if (x - (pw[i + 1] - 2) <= 0) return sum;
  }
  return sum;
}
int main() {
  cin >> q;
  pw[0] = 1LL;
  for (int i = 1; i <= 10; ++i) {
    pw[i] = pw[i - 1] * 10LL;
  }
  for (int cas = 1; cas <= q; ++cas) {
    long long k;
    cin >> k;
    long long l = 1, r = 1000000000LL;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (getsum(mid) >= k)
        r = mid;
      else
        l = mid + 1;
    }
    k -= getsum(r - 1);
    long long sum2 = 9;
    long long cnt = 1;
    while (k > sum2 * cnt) {
      k -= sum2 * cnt;
      sum2 *= 10;
      cnt++;
    }
    long long num = pw[cnt - 1] + (k + cnt - 1) / cnt - 1;
    if (k % cnt == 0) {
      cout << num % 10 << endl;
    } else {
      int r = k % cnt;
      cout << num / pw[cnt - r] % 10 << endl;
    }
  }
  return 0;
}
