#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
void scan() {}
template <typename F, typename... R>
void scan(F& f, R&... r) {
  cin >> f;
  scan(r...);
}
int di_;
string dnms_, co_ = ",";
void debug_() { cout << endl; }
template <typename F, typename... R>
void debug_(F& f, R&... r) {
  while (dnms_[di_] != ',') cout << dnms_[di_++];
  di_++;
  cout << ": " << f << ",";
  debug_(r...);
}
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "";
  for (auto it = a.begin(); it != a.end(); it++) {
    if (it != a.begin()) out << " ";
    out << *it;
  }
  out << "";
  return out;
}
template <class A, class B>
istream& operator>>(istream& in, pair<A, B>& a) {
  in >> a.first >> a.second;
  return in;
}
template <class A>
istream& operator>>(istream& in, vector<A>& a) {
  for (A& i : a) in >> i;
  return in;
}
long long int fastexpo(long long int x, long long int y) {
  if (y == 0) return 1;
  if (y % 2 == 0)
    return fastexpo(x * x, y / 2);
  else
    return x * fastexpo(x * x, y / 2);
}
long long int sumagp(long long int n, long long int k) {
  long long int p = fastexpo(10, k);
  long long int sum = k * p - ((p - 1) / 9) + (n - p + 1) * (k + 1);
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long int> csum(1);
  vector<long long int> nsum(1);
  long long int k = 0, pk = 10;
  nsum[0] = 0;
  csum[0] = 0;
  for (int i = 1;; i++) {
    if (i / pk) {
      k++;
      pk *= 10;
    }
    nsum.push_back(sumagp(i, k));
    csum.push_back(csum.back() + nsum.back());
    if (csum.back() > 1e9) break;
  }
  int t;
  cin >> t;
  while (t--) {
    int qk, ans;
    cin >> qk;
    auto it = lower_bound(csum.begin(), csum.end(), qk);
    int n = distance(csum.begin(), it);
    int tot = csum[n];
    if (tot == qk) {
      ans = n % 10;
      cout << ans << endl;
      continue;
    }
    int rem = qk - csum[n - 1];
    it = lower_bound(nsum.begin(), nsum.end(), rem);
    int nk = distance(nsum.begin(), it);
    if (rem == nsum[nk]) {
      ans = nk % 10;
      cout << ans << endl;
      continue;
    }
    rem -= nsum[nk - 1];
    vector<int> dig;
    int nk_ = nk;
    while (nk_ != 0) {
      dig.push_back(nk_ % 10);
      nk_ /= 10;
    }
    reverse(dig.begin(), dig.end());
    ans = dig[rem - 1];
    cout << ans << endl;
  }
  return 0;
}
