#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const long long maxn = 52849 + 10000;
long long int s[maxn + 4], p[maxn + 4], k[maxn + 4];
inline long long getsum(long long k) {
  long long sum = 0;
  while (k) {
    sum++;
    k /= 10;
  }
  return sum;
}
int main() {
  s[1] = 1;
  int cnt = 1;
  p[0] = 0;
  k[0] = 0;
  for (int i = 1; i <= 52849; i++) s[i] = getsum(i);
  for (int i = 1; i <= 52849; i++) p[i] = p[i - 1] + s[i];
  for (int i = 1; i <= 52849; i++) k[i] = p[i] + k[i - 1];
  int t;
  scanf("%d", &t);
  int left, pos;
  while (t--) {
    int num;
    scanf("%d", &num);
    left = lower_bound(k + 1, k + 52845, num) - (k + 1);
    pos = num - k[left];
    left = lower_bound(p + 1, p + 52845, pos) - (p + 1);
    pos = pos - p[left];
    left++;
    pos = s[left] - pos + 1;
    int i = 1;
    while (i < pos) {
      left /= 10;
      i++;
    }
    cout << left % 10 << endl;
  }
  return 0;
}
