#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k, q, num, x, c, dig = 1, a[447194];
  cin >> q;
  dig = 1;
  long long pc = 1, pro = 1;
  num = 2;
  x = 10;
  c = 0;
  a[0] = 0;
  a[1] = 1;
  while (dig <= 100000000011) {
    dig += a[num - 1] - a[num - 2] + c + 1;
    num++;
    if (num / x) {
      c++;
      pc = 1;
      x = x * 10;
    }
    a[num - 1] = dig;
  }
  while (q--) {
    cin >> k;
    long long t = k;
    long long l = 1, r = 44718, mid;
    while (l <= r) {
      mid = (l + r) / 2;
      if (t > a[mid]) {
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    r++;
    long long p = k - a[r - 1];
    long long p1 = 1;
    long long p2 = 1;
    long long cou = 1;
    long long c[10] = {};
    c[0] = 0;
    for (long long i = 1; i <= 9; i++) {
      p2 *= 10;
      c[i] = c[i - 1] + (p2 - p1) * cou;
      if (c[i] >= p) {
        break;
      } else {
        p1 *= 10;
        cou++;
      }
    }
    long long f = 1;
    long long tt = p - c[cou - 1];
    if (tt % cou) {
      long long ss = pow(10, cou - 1);
      ss += tt / cou;
      string arithmos = std::to_string(ss);
      cout << arithmos[tt % cou - 1] << endl;
    } else {
      long long ss = pow(10, cou - 1);
      ss += tt / cou;
      cout << (ss - 1) % 10 << endl;
    }
  }
}
