#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const double PI = acos(-1.);
const int N = 4e5 + 5;
const int K = 1e5 + 5;
const int Ai = 1e6 + 6;
const int LOGN = 30;
long long digit(long long x) {
  long long res = 0;
  while (x) {
    res++;
    x /= 10;
  }
  return res;
}
long long calc(long long x, long long m) {
  string s;
  while (x) {
    s.push_back((x % 10) + '0');
    x /= 10;
  }
  reverse(s.begin(), s.end());
  return s[m] - '0';
}
long long solve(long long x) {
  long long p = 90;
  long long pp = 10;
  long long d = 2;
  if (x < 10) return x;
  x -= 9;
  while (true) {
    if (x <= d * p) {
      x--;
      long long m = x % d;
      long long yy = pp + x / d;
      return calc(yy, m);
    } else {
      x -= d * p;
      d++;
      pp *= 10;
      p *= 10;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long sum = 0;
    long long cnt = 1;
    long long x = 1;
    while (true) {
      if (sum + cnt >= k) {
        k -= sum;
        cout << solve(k) << "\n";
        break;
      } else {
        sum += cnt;
        x++;
        cnt += digit(x);
      }
    }
  }
  return 0;
}
