#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> num(1, 0);
  vector<long long> arr(1, 0);
  for (int i = 1; i <= 1e5; i++) {
    num.push_back(num.back() + 1 + floor(log10(i)));
    arr.push_back(arr.back() + num.back());
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    x--;
    x -= *--upper_bound(arr.begin(), arr.end(), x);
    int p = upper_bound(num.begin(), num.end(), x) - num.begin();
    x -= num[p - 1];
    x = floor(log10(p)) - x;
    while (x--) p /= 10;
    cout << p % 10 << '\n';
  }
}
