#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
void calc() {
  long long n;
  cin >> n;
  n--;
  long long blockc = 0, dn = 1, base = 1, slen = 0;
  while (1) {
    long long bn = 9 * base;
    long long rlen = slen + bn * dn;
    blockc = (slen + rlen + dn) * bn / 2;
    if (n - blockc < 0) break;
    n -= blockc;
    slen = rlen;
    dn++;
    base *= 10;
  }
  long double delta = sqrtl((long double)(slen + dn * 0.5) * (slen + dn * 0.5) +
                            (long double)2 * dn * n);
  long long pos = (-slen + delta) / dn;
  long long lin = pos;
  if (n < (slen * 2 + dn + lin * dn) * lin / 2) lin--;
  n -= (slen * 2 + dn + lin * dn) * lin / 2;
  base = 1, dn = 1;
  while (1) {
    long long slic = base * 9 * dn;
    if (n - slic < 0) break;
    n -= slic;
    base *= 10;
    dn++;
  }
  long long num = n / dn + base;
  n %= dn;
  for (int i = 0; i < dn - n - 1; i++) num /= 10;
  cout << num % 10 << '\n';
}
int main() {
  int q;
  cin >> q;
  while (q--) calc();
  return 0;
}
