#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long q, n;
long long mypow(long long a, long long b) {
  long long res = 1;
  for (long long i = 1; i <= b; i++) res *= a;
  return res;
}
long long st[20], cou[20], ed[20];
long long val(long long n, long long a1, long long d) {
  if (n <= 0) return 0;
  return n * a1 + n * (n - 1) / 2 * d;
}
void inti() {
  st[1] = 1;
  ed[1] = 9;
  cou[1] = val(9, st[1], 1);
  for (int i = 2; i <= 20; i++) {
    long long zz = mypow(10, i) - mypow(10, i - 1);
    st[i] = ed[i - 1] + i;
    ed[i] = st[i] + (zz - 1) * i;
    cou[i] = val(zz, st[i], i);
    if (cou[i] > 1e18) break;
  }
}
long long check(long long mid, long long sta, long long d) {
  long long cnt = (mid - sta) / d + 1;
  return val(cnt, sta, d);
}
long long zzz[15];
void init() {
  zzz[1] = 9;
  for (int i = 2; i <= 10; i++) zzz[i] = i * (mypow(10, i) - mypow(10, i - 1));
}
int main() {
  inti();
  init();
  cin >> q;
  while (q--) {
    cin >> n;
    long long cur = 0, tot = 0, nn = n;
    for (int i = 1; i <= 10; i++) {
      tot += cou[i];
      if (tot >= n) {
        cur = i;
        break;
      }
      nn -= cou[i];
    }
    long long l = st[cur], r = ed[cur];
    while (l < r) {
      long long mid = l + r + 1 >> 1;
      if (check(mid, st[cur], cur) >= nn)
        r = mid - 1;
      else
        l = mid;
    }
    long long ans2 = l + 1;
    long long ans = mypow(10, cur - 1) + (ans2 - st[cur]) / cur;
    nn -= val(ans - mypow(10, cur - 1), st[cur], cur);
    if (nn == 0) {
      cout << (ans - 1) % 10 << endl;
      continue;
    }
    long long my = 0;
    for (int i = 1; i <= 10; i++) {
      if (zzz[i] < nn)
        nn -= zzz[i];
      else {
        my = i;
        break;
      }
    }
    long long cs = 0, ys = 0, curval = 0;
    if (my == 0)
      cs = nn;
    else {
      cs = nn / my;
      ys = nn % my;
      if (ys == 0) cs--;
    }
    curval = mypow(10, my - 1) + cs;
    if (ys == 0) {
      cout << curval % 10 << endl;
      continue;
    }
    int kkk[20];
    for (int i = 0; i <= 10; i++) kkk[i] = 0;
    int ccc = 0;
    while (curval) {
      kkk[++ccc] = curval % 10;
      curval /= 10;
    }
    for (int i = ccc, abc = 1; i > 0; i--, abc++) {
      if (abc == ys) {
        cout << kkk[i] << endl;
        break;
      }
    }
  }
}
