#include <bits/stdc++.h>
using namespace std;
int nod(int x) {
  int cnt = 0;
  while (x) {
    cnt++;
    x = x / 10;
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<long long> v(1e6 + 5), pre(1e6 + 5, 0);
  v[1] = 1;
  pre[1] = 1;
  int cur = 1;
  for (int i = 2; i < 1e6 + 5; i++) {
    if (i == 10 || i == 100 || i == 1000 || i == 10000 || i == 100000 ||
        i == 1000000)
      cur++;
    v[i] = v[i - 1] + cur;
    pre[i] = pre[i - 1] + v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    int x = lower_bound(pre.begin(), pre.end(), k) - pre.begin();
    if (k == pre[x]) {
      cout << x % 10 << endl;
    } else {
      k -= pre[x - 1];
      int y = lower_bound(v.begin(), v.end(), k) - v.begin();
      k = v[y] - k;
      while (k) {
        k--;
        y /= 10;
      }
      cout << y % 10 << endl;
    }
  }
  return 0;
}
