#include <bits/stdc++.h>
using namespace std;
long long len[1000005];
string s = "0";
int q, k;
int read();
int main() {
  len[1] = 1;
  long long sin_len = 1, check = 10;
  for (int i = 2; i <= 1000000; i++) {
    if (i / check) {
      sin_len++;
      check *= 10;
    }
    len[i] = len[i - 1] + (len[i - 1] - len[i - 2]) + sin_len;
  }
  stringstream ss;
  for (int i = 1; i <= 21837; i++) {
    ss << i;
  }
  s += ss.str();
  q = read();
  int tag;
  for (int i = 1; i <= q; i++) {
    k = read();
    for (int j = 1; j <= 22000; j++) {
      if (len[j] >= k) {
        k -= len[j - 1];
        break;
      }
    }
    cout << s[k] << endl;
  }
}
int read() {
  int ret = 0, flag = 0;
  char ch = getchar();
  if (ch == '-') {
    flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  if (flag)
    return -ret;
  else
    return ret;
}
