#include <bits/stdc++.h>
using namespace std;
long long st[201], ed[201], sum[201], bbww[100];
long long sttt[12] = {0,        0,         10,         100,
                      1000,     10000,     100000,     1000000,
                      10000000, 100000000, 1000000000, 10000000000};
void init() {
  st[0] = 0;
  ed[0] = 0;
  long long num = 9;
  for (long long i = 1; i < 64; ++i) {
    st[i] = ed[i - 1] + i;
    ed[i] = st[i] + i * (num - 1);
    sum[i] = sum[i - 1] + (st[i] + ed[i]) * num / 2;
    if (sum[i] >= 1e18) break;
    num *= 10;
  }
}
int main(int argc, char const *argv[]) {
  init();
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ww = 0;
    long long ans = 0;
    for (long long i = 0; i < 11; ++i) {
      if (sum[i] >= n) {
        ww = i;
        ans = n - sum[i - 1];
        break;
      }
    }
    long long mid = (9 * pow(10, ww - 1)) / 2;
    if (ans <= st[ww])
      mid = 1;
    else {
      long long left = 1, right = (9 * pow(10, ww - 1));
      while (left <= right) {
        mid = (left + right) / 2;
        if (((2 * st[ww] + (mid - 1) * ww) * mid / 2 >= ans) &&
            ((2 * st[ww] + (mid - 2) * ww) * (mid - 1) / 2 < ans))
          break;
        else {
          if ((2 * st[ww] + (mid - 1) * ww) * mid / 2 > ans) {
            right = mid - 1;
          } else
            left = mid + 1;
        }
      }
    }
    ans = ans - ((2 * st[ww] + (mid - 2) * ww) * (mid - 1) / 2);
    int www = 0;
    for (int i = 0; i < 11; ++i) {
      if (ed[i] >= ans) {
        www = i;
        ans = ans - ed[i - 1];
        break;
      }
    }
    long long aaa = ans % www;
    long long bbb = sttt[www] + (ans / www);
    if (ans % www == 0 && www != 1) bbb -= 1;
    long long bbz = bbb;
    long long tt = 0;
    while (bbz != 0) {
      bbww[tt] = bbz % 10;
      bbz /= 10;
      tt++;
    }
    if (aaa == 0)
      cout << bbww[aaa] << endl;
    else
      cout << bbww[tt - aaa] << endl;
  }
  return 0;
}
