#include <bits/stdc++.h>
using namespace std;
long long count(int mid, int op) {
  long long sum = 0, add = 0, cnt = 0, len = 0, mi = 1;
  while (1) {
    len++;
    mi *= 10;
    cnt = mi - mi / 10;
    if (mid >= mi) {
      if (op) {
        sum += add * cnt + (cnt + 1) * cnt / 2 * len;
        add += cnt * len;
      } else
        sum += cnt * len;
    } else {
      cnt = mid - mi / 10 + 1;
      if (op) {
        sum += add * cnt + (cnt + 1) * cnt / 2 * len;
        add += cnt * len;
      } else
        sum += cnt * len;
      break;
    }
  }
  return sum;
}
int main() {
  int q;
  long long k;
  cin >> q;
  while (q--) {
    cin >> k;
    int l = 1, r = 1e9;
    while (l <= r) {
      int mid = l + r >> 1;
      if (count(mid, 1) < k)
        l = mid + 1;
      else
        r = mid - 1;
    }
    k -= count(r, 1);
    r = r + 1, l = 1;
    while (l <= r) {
      int mid = l + r >> 1;
      if (count(mid, 0) < k)
        l = mid + 1;
      else
        r = mid - 1;
    }
    k -= count(r, 0);
    cout << to_string(r + 1)[k - 1] << endl;
  }
  return 0;
}
