#include <bits/stdc++.h>
using namespace std;
int length = 80000;
int tn[80000];
int getLength(int num) {
  int length = 0;
  while (num / 10 != 0) {
    num /= 10;
    length++;
  }
  return length + 1;
}
void go() {
  tn[0] = 0;
  tn[1] = 1;
  for (int i = 1; i < length; i++) {
    tn[i] = tn[i - 1] + getLength(i);
  }
}
int getNumFromIntegerByIndex(int number, int index) {
  int length = getLength(number);
  for (int i = 0; i < length - index; i++) {
    number /= 10;
  }
  return number % 10;
}
int findFromNumber(int index) {
  for (int t = 1; t < length; t++) {
    if (index <= tn[t]) {
      return getNumFromIntegerByIndex(t, index - tn[t - 1]);
    }
  }
  return 0;
}
int solve(int index) {
  for (int i = 1; i < length; i++) {
    if (index > tn[i]) {
      index -= tn[i];
    } else if (index < tn[i]) {
      return findFromNumber(index);
    } else {
      return getNumFromIntegerByIndex(i, getLength(i));
    }
  }
  return 0;
}
int main() {
  go();
  int t;
  cin >> t;
  while (t--) {
    int k, ans = 1;
    scanf("%d", &k);
    cout << solve(k) << endl;
  }
  return 0;
}
