#include <bits/stdc++.h>
using namespace std;
const int N = 32;
int sum(int n) { return n * (n + 1) / 2; }
long long block(long long n) {
  int p = (int)log10(n);
  long long ans = 0;
  int digit = 1;
  for (int j = 0; j <= p; j++) {
    int nines = digit - 1;
    ans += (sum(n) - sum(nines) - (n - nines) * nines);
    digit *= 10;
  }
  return ans;
}
int Binsearch(int k, long long l = 0, long long r = 21900) {
  int ans = 0;
  while (l < r) {
    long long mid = l + (r - l) / 2;
    if (block(mid) < k) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    int n = Binsearch(k);
    int d = k - block(n);
    int last = 1;
    for (int i = 1; i <= n + 1 && d > 0; i++) {
      int rev = 0;
      vector<int> digits;
      int tmp = i;
      while (tmp > 0) {
        digits.push_back(tmp % 10);
        tmp = tmp / 10;
      }
      reverse(digits.begin(), digits.end());
      for (int j = 0; j < (int)digits.size() && d > 0; j++, d--) {
        last = digits[j];
      }
    }
    cout << last << endl;
  }
  return 0;
}
