#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p[11] = {0,         9,          189,        2889,
                     38889,     488889,     5888889,    68888889,
                     788888889, 8888888889, 98888888889},
            v[10] = {0,
                     45,
                     9045,
                     1395495,
                     189414495,
                     23939649495,
                     2893942449495,
                     339393974949495,
                     38939394344949495,
                     4393939398494949495},
            powu[11] = {1,         10,         100,        1000,
                        10000,     100000,     1000000,    10000000,
                        100000000, 1000000000, 10000000000};
  long long x = 0, st = 0, dr = 0, m = 0, poz = 0, calcul = 0, auxx = 0, nr = 0;
  int contor1, contor, nrcif;
  cin >> contor;
  for (contor1 = 1; contor1 <= contor; contor1++) {
    cin >> x;
    st = 0;
    while (v[st] < x) st++;
    st--;
    poz = st;
    st = 0;
    dr = powu[poz + 1] - powu[poz];
    while (st <= dr) {
      m = (st + dr) / 2;
      if (poz)
        calcul =
            v[poz] + p[poz] * (m + 1) + ((poz + 1) * (m + 1) * (m + 2)) / 2;
      else
        calcul = v[poz] + p[poz] * m + ((poz + 1) * m * (m + 1)) / 2;
      if (calcul < x)
        st = m + 1;
      else if (calcul > x)
        dr = m - 1;
      else {
        st = dr = m;
        break;
      }
    }
    if (poz)
      calcul = v[poz] + p[poz] * st + ((poz + 1) * st * (st + 1)) / 2;
    else
      calcul = v[poz] + p[poz] * (st - 1) + ((poz + 1) * (st - 1) * (st)) / 2;
    x = x - calcul;
    st = 0;
    while (p[st] < x) st++;
    st--;
    if ((x - p[st]) % (st + 1) == 0)
      nr = (x - p[st]) / (st + 1) + powu[st] - 1;
    else {
      x -= p[st];
      nr = x / (st + 1) + powu[st];
      x = x % (st + 1);
      nrcif = st + 1;
      while (nrcif > x) {
        nr /= 10;
        nrcif--;
      }
    }
    cout << nr % 10 << '\n';
  }
  return 0;
}
