#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const int maxn = 2e5 + 20;
long long a[maxn];
long long b[maxn];
void init() {
  long long mark = 10;
  long long digit = 1;
  a[0] = 0;
  a[1] = 1;
  for (long long i = 2; i < 30000; i++) {
    if (i % mark == 0) {
      digit++;
      mark = mark * 10;
    }
    a[i] = a[i - 1] + digit;
  }
  for (long long i = 1;; i++) {
    b[i] = b[i - 1] + a[i];
    if (b[i] >= 999999999) {
      break;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  init();
  int n = 21836;
  while (q--) {
    long long t;
    cin >> t;
    long long pos = lower_bound(b + 1, b + n, t) - b;
    long long rest = t - b[pos - 1];
    pos = lower_bound(a + 1, a + n, rest) - a;
    rest = rest - a[pos - 1];
    int mm[20];
    int coun = 0;
    while (pos) {
      mm[coun++] = pos % 10;
      pos /= 10;
    }
    for (int i = coun - 1; i >= 0; i--) {
      rest--;
      if (rest == 0) {
        cout << mm[i] << endl;
        break;
      }
    }
  }
  return 0;
}
