#include <bits/stdc++.h>
using namespace std;
long long n, f[100001], ff[100001];
void wrtt(long long x, long long n) {
  n -= ff[x];
  x++;
  long long kk = 1;
  while (kk <= x) kk *= 10LL;
  while (n) {
    n--;
    kk /= 10LL;
  }
  printf("%lld\n", x / kk % 10);
}
void write(long long x, long long n) {
  n -= f[x];
  auto vv = lower_bound(ff + 1, ff + 100001, n);
  vv--;
  wrtt(vv - ff, n);
}
void work() {
  scanf("%lld", &n);
  auto v = lower_bound(f + 1, f + 100001, n);
  v--;
  write(v - f, n);
}
void init() {
  for (int i = 1; i < 100001; i++) {
    int t = i;
    f[i] = f[i - 1];
    ff[i] = ff[i - 1];
    while (t) {
      ff[i]++;
      t /= 10;
    }
    f[i] += ff[i];
  }
}
int main() {
  int t;
  init();
  scanf("%d", &t);
  while (t--) work();
  return 0;
}
