#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  for (char& c : s) c = c == ',' ? ' ' : c;
  stringstream ss;
  ss << s;
  vector<string> res;
  for (string z; ss >> z; res.push_back(z))
    ;
  return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
  if (idx > 0) cerr << ", ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, T...);
}
void localTest() {}
const long long N = 1e5 + 5;
long long dp[N];
long long solve(long long x) { return dp[x]; }
int main() {
  localTest();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  dp[1] = 1;
  for (long long i = 2; i < N; ++i) {
    char dig[10];
    sprintf(dig, "%lld", i);
    long long len = strlen(dig);
    dp[i] = 2 * dp[i - 1] - dp[i - 2] + len;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long lo = 1, hi = 1e5, ans = 1;
    while (lo <= hi) {
      long long mid = (lo + hi) >> 1;
      if (solve(mid) <= k) {
        ans = mid;
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    if (solve(ans) == k) {
      cout << ans % 10 << "\n";
    } else {
      k -= solve(ans);
      for (long long i = 1; i <= ans + 1; ++i) {
        char dig[10];
        sprintf(dig, "%lld", i);
        long long sz = strlen(dig);
        if (sz < k) {
          k -= sz;
        } else {
          cout << dig[k - 1] << "\n";
          break;
        }
      }
    }
  }
  return 0;
}
