#include <bits/stdc++.h>
using namespace std;
long long gets(long long mm, int opt) {
  long long sum = 0, cnt, add = 0, len = 0, exam = 1;
  while (1) {
    exam *= 10;
    len++;
    if (mm > exam - 1) {
      cnt = exam - exam / 10;
      if (opt) {
        sum += add * cnt + cnt * (cnt + 1) / 2 * len;
        add += cnt * len;
      } else {
        sum += cnt * len;
      }
    } else {
      cnt = mm - exam / 10 + 1;
      if (opt) {
        sum += add * cnt + cnt * (cnt + 1) / 2 * len;
        add += cnt * len;
      } else {
        sum += cnt * len;
      }
      break;
    }
  }
  return sum;
}
int main() {
  int q;
  long long k;
  long long ans = 0;
  scanf("%d", &q);
  while (q--) {
    ans = 0;
    scanf("%lld", &k);
    long long l = 0, r = 1e9;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (gets(mid, 1) < k) {
        l = mid + 1;
        ans = mid;
      } else {
        r = mid - 1;
      }
    }
    k -= gets(ans, 1);
    l = 0;
    r = ans + 1;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (gets(mid, 0) < k) {
        l = mid + 1;
        ans = mid;
      } else {
        r = mid - 1;
      }
    }
    k -= gets(ans, 0);
    ans += 1;
    cout << to_string(ans)[k - 1] << endl;
  }
}
