#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
const long long MOD = 1e9 + 7;
vector<long long> adj[MAXN];
long long po[20];
long long block(long long x) {
  if (x == 0) return 0;
  string s = to_string(x);
  long long t = s.size();
  long long ans = 0;
  for (long long i = 1; i <= t; i++) {
    long long mn = x - po[i] + 1;
    long long mx = x - min(x, po[i + 1] - 1) + 1;
    long long cnt = min(po[i + 1] / 10 * 9, x - po[i] + 1);
    ans += i * ((mn + mx) * cnt / 2);
  }
  return ans;
}
void solve(long long tc) {
  po[1] = 1;
  for (long long i = 2; i < 20; i++) po[i] = po[i - 1] * 10ll;
  long long k;
  cin >> k;
  for (long long i = 1; i <= 50000; i++) {
    if (block(i) >= k) {
      long long prev = block(i - 1);
      k -= prev;
      string str;
      for (long long j = 1; j <= i; j++) {
        str += to_string(j);
      }
      cout << str[k - 1] << endl;
      return;
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  cin >> t;
  long long cnt = 0;
  while (t--) solve(++cnt);
}
