#include <bits/stdc++.h>
using namespace std;
const int MX = 50007;
int v[MX];
int main() {
  for (int i = 1; i < MX; ++i) {
    int cur = i, pw = 1;
    while (cur - (pw - 1) > 0) {
      v[i] += cur - (pw - 1);
      pw *= 10;
    }
    v[i] += v[i - 1];
  }
  int q;
  cin >> q;
  for (int _ = 0; _ < q; ++_) {
    int k;
    cin >> k;
    int lo = 1, hi = MX - 1;
    while (lo < hi) {
      int m = (lo + hi) / 2;
      if (v[m] >= k) {
        hi = m;
      } else {
        lo = m + 1;
      }
    }
    k -= v[lo - 1];
    k--;
    string s = "";
    int cur = 1;
    while (k >= s.size()) {
      s += to_string(cur);
      cur++;
    }
    cout << s[k] << endl;
  }
  return 0;
}
