#include <bits/stdc++.h>
using namespace std;
int64_t Pow(int64_t x, int64_t y) {
  if (!y) return 1;
  int64_t tmp = Pow(x, y / 2);
  if (y % 2) return tmp * tmp * x;
  return tmp * tmp;
}
int64_t Calc(int64_t i) {
  int64_t len = 0, tmp = i;
  do {
    ++len;
    tmp /= 10;
  } while (tmp);
  int64_t ans = 0;
  int64_t add = 0;
  for (int j = 1; j <= len; ++j) {
    int64_t cnt;
    if (j == len)
      cnt = i - Pow(10, j - 1) + 1;
    else
      cnt = Pow(10, j) - Pow(10, j - 1);
    ans += cnt * add + cnt * (cnt + 1) / 2 * j;
    add += cnt * j;
  }
  return ans;
}
int Search(int64_t x, int64_t index) {
  int64_t len = 0, tmp = x;
  do {
    ++len;
    tmp /= 10;
  } while (tmp);
  int64_t num;
  for (int j = 1; j <= len; ++j) {
    int64_t cnt;
    if (j == len)
      cnt = x - Pow(10, j - 1) + 1;
    else
      cnt = Pow(10, j) - Pow(10, j - 1);
    index -= cnt * j;
    if (index <= 0) {
      index += cnt * j;
      num = (index + j - 1) / j;
      num += Pow(10, j - 1) - 1;
      index -= (num - Pow(10, j - 1)) * j;
      break;
    }
  }
  vector<int> digit;
  do {
    digit.push_back(num % 10);
    num /= 10;
  } while (num);
  return digit[digit.size() - index];
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int64_t k;
    cin >> k;
    int64_t l = 1, r = 1000000000, ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (Calc(mid) >= k) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << Search(ans, k - Calc(ans - 1)) << endl;
  }
  return 0;
}
