#include <bits/stdc++.h>
using namespace std;
vector<long long> sum;
vector<long long> digit;
long long Pow[100005];
void precal() {
  sum.push_back(0);
  digit.push_back(0);
  for (long long i = 1; i <= 100000; i++) {
    long long d = log10(i) + 1;
    digit.push_back(digit[i - 1] + d);
    sum.push_back(sum[i - 1] + digit[i]);
  }
  long long k = 10;
  for (long long i = 1; i <= 10; i++) {
    Pow[i] = k;
    k *= 10;
  }
}
int main() {
  precal();
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n;
    cin >> n;
    long long idx = lower_bound(sum.begin(), sum.end(), n) - sum.begin();
    if (sum[idx] >= n) idx--;
    n -= sum[idx];
    long long id = lower_bound(digit.begin(), digit.end(), n) - digit.begin();
    if (digit[id] >= n) id--;
    long long num = id + 1;
    long long d = log10(num) + 1;
    n -= digit[id];
    long long pos = Pow[d - n + 1];
    long long ans = (num % pos) / (pos / 10);
    cout << ans << endl;
  }
  return 0;
}
