#include <bits/stdc++.h>
using namespace std;
long long int find_digits(long long int seg) {
  long long int count = 0;
  while (seg > 0) {
    seg = seg / 10;
    count++;
  }
  return count;
}
long long int find_num(long long int k, long long int ans) {
  long long int count = find_digits(k);
  count = count - ans + 1;
  ans = 1;
  while (k > 0) {
    if (ans == count) {
      return k % 10;
    }
    ans++;
    k = k / 10;
  }
}
long long int find(vector<long long int> &dp, long long int seg,
                   long long int k, long long int sum) {
  long long int n = find_digits(seg);
  dp[seg] = dp[seg - 1] + n;
  sum = dp[seg] + sum;
  if (sum < k) {
    return find(dp, seg + 1, k, sum);
  } else {
    k = sum - k;
    return dp[seg] - k;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    long long int k;
    cin >> k;
    vector<long long int> dp(25000, 0);
    dp[1] = 1;
    long long int sum = 1;
    int ans;
    if (k == 1)
      ans = 1;
    else
      ans = find(dp, 2, k, sum);
    long long int j;
    for (j = 0; j <= ans; j++) {
      if (dp[j] >= ans) break;
    }
    ans = ans - dp[j - 1];
    ans = find_num(j, ans);
    cout << ans << endl;
  }
}
