#include <bits/stdc++.h>
using namespace std;
inline stringstream i_line() {
  string line;
  getline(cin, line);
  return stringstream(line);
}
inline int64_t digts_up_to(int64_t n) {
  if (n == 0) {
    return 1;
  }
  assert(n >= 1);
  int64_t res = 0;
  int64_t pow10 = 1;
  while (true) {
    auto to_count = n - (pow10 - 1);
    if (to_count > 0) {
      res += to_count;
      pow10 *= 10;
    } else {
      break;
    }
  }
  return res;
}
inline int64_t digts_from_to(int64_t a, int64_t b) {
  assert(a < b);
  assert(a > 1);
  return digts_up_to(b) - digts_up_to(a - 1);
}
void digits(int64_t n, deque<int32_t> &res) {
  deque<int32_t> ds;
  while (n != 0) {
    ds.push_front(n % 10);
    n /= 10;
  }
  for (auto d : ds) {
    res.push_back(d);
  }
}
int main() {
  vector<int64_t> index;
  index.reserve(22000);
  int64_t indexed = 0;
  int64_t i = 1;
  while (indexed < 1000000000) {
    int64_t counted = digts_up_to(i);
    index.push_back(indexed + counted);
    indexed += counted;
    i += 1;
  }
  uint32_t tc;
  cin >> tc;
  for (uint32_t tc_i = 0; tc_i < tc; tc_i++) {
    uint32_t k;
    cin >> k;
    int64_t low = 0;
    int64_t high = index.size();
    bool found = false;
    while (low <= high) {
      ;
      ;
      int64_t mid = (low + high) / 2;
      int64_t prev;
      if (mid > 0) {
        prev = index[mid - 1];
      } else {
        prev = 0;
      };
      ;
      ;
      if (k > prev && k <= index[mid]) {
        auto steps = k - prev;
        int i = 1;
        deque<int32_t> availble;
        while (availble.size() < steps) {
          digits(i, availble);
          i += 1;
        }
        cout << availble[steps - 1] << endl;
        found = true;
        break;
      } else {
        if (k <= prev) {
          high = mid - 1;
        } else {
          low = mid + 1;
        }
      }
    }
    if (!found) {
      cout << "Not found" << endl;
      cout << low << endl;
      cout << high << endl;
      cout << 1 << endl;
    }
  }
  return 0;
}
