#include <bits/stdc++.h>
using namespace std;
int l[80009];
int c[80009];
int s[80009];
int length(int x) {
  if (x >= 10000) {
    return 5;
  } else if (x >= 1000) {
    return 4;
  } else if (x >= 100)
    return 3;
  else if (x >= 10)
    return 2;
  else
    return 1;
}
void init() {
  for (int i = 1; i <= 60000; i++) {
    l[i] = length(i);
    c[i] = c[i - 1] + l[i];
    s[i] = s[i - 1] + c[i];
  }
}
int main() {
  int t, pp;
  init();
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int index = lower_bound(s + 1, s + 60000, n) - s;
    n -= s[index - 1];
    index = lower_bound(c + 1, c + index, n) - c;
    n -= c[index - 1];
    n = l[index] - n;
    while (n--) {
      index /= 10;
    }
    printf("%d\n", index % 10);
  }
  return 0;
}
