#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<long long> presum(maxn, 0);
int main() {
  int last = 0;
  for (long long i = 1; i < maxn; ++i) {
    presum[i] = presum[i - 1] + min(i, 9LL);
    if (i >= 10 && i < 100) {
      presum[i] = presum[i] + (2LL * (i - 9LL));
    } else if (i >= 100 && i < 1000) {
      presum[i] = presum[i] + (2LL * 90LL) + (3LL * (i - 99LL));
    } else if (i >= 1000 && i < 10000) {
      presum[i] =
          presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * (i - 999LL));
    } else if (i >= 10000 && i < 100000) {
      presum[i] = presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * 9000LL) +
                  (5LL * (i - 9999LL));
    } else if (i >= 100000 && i < 1000000) {
      presum[i] = presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * 9000LL) +
                  (5LL * 90000LL) + (6LL * (i - 99999LL));
    } else if (i >= 1000000 && i < 10000000) {
      presum[i] = presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * 9000LL) +
                  (5LL * 90000LL) + (6LL * 900000LL) + (7LL * (i - 999999LL));
    }
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    int it = lower_bound(presum.begin(), presum.end(), k) - presum.begin();
    string aux = "";
    for (int i = 1; i <= it; ++i) {
      aux += to_string(i);
    }
    cout << aux[k - (presum[it - 1] + 1)] << '\n';
  }
  return 0;
}
