#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k, d, t, s, e, l, i, m, x, y, ans, cnt, p;
  int q;
  cin >> q;
  while (q > 0) {
    cin >> k;
    k--;
    d = 1;
    t = 10;
    s = 1;
    e = 1;
    while (k > 0) {
      d++;
      if (d >= t) {
        e++;
        t *= 10;
      }
      s += e;
      k -= s;
    }
    k += s;
    m = 9;
    cnt = 1;
    while (k > m) {
      cnt++;
      m += cnt * 9 * pow(10, cnt - 1);
    }
    m -= cnt * 9 * pow(10, cnt - 1);
    x = (k - m) / cnt;
    if ((k - m) % cnt != 0) x++;
    y = (k - m) % cnt;
    if (y == 0) y = cnt;
    y = cnt - y;
    p = pow(10, cnt - 1) - 1 + x;
    ans = p / (pow(10, y));
    ans %= 10;
    cout << ans << endl;
    q--;
  }
}
