#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long q = n;
  while (q--) {
    long pos;
    cin >> pos;
    string block = "";
    string add;
    long long s = block.size(), prev = 0;
    vector<string> vec;
    for (int i = 1; i <= 5 * 10000; i++) {
      prev = prev + add.size();
      add = std::to_string(i);
      s += prev + add.size();
      vec.push_back(add);
      if (s >= pos) {
        break;
      }
    }
    long long mi_it = s - prev - add.size();
    long long new_pos = pos - mi_it;
    for (int i = 0; i < vec.size(); i++) {
      block += vec[i];
    }
    cout << block[new_pos - 1] - '0' << endl;
  }
  return 0;
}
