#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 2e5 + 10;
const long long inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
long long area(long long x1, long long y1, long long x2, long long y2,
               long long a, long long b, long long c, long long d) {
  long long l = max(a, x1), r = min(x2, c), down = max(y1, b), up = min(y2, d);
  if (l > r) return 0;
  if (down > up) return 0;
  return (up - down) * (r - l);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long s = 0, i;
    for (i = 1; i <= k; i++) {
      s += i;
      int j = 10, cnt = 1;
      while (i >= j) {
        int r;
        if (j * 10 <= i)
          r = j * 10 - 1;
        else
          r = i;
        s += cnt * (r - j + 1);
        j *= 10, cnt++;
      }
      if (s >= k) break;
    }
    int ans = -1;
    for (i; i >= 1; i--) {
      int ti = i;
      while (ti) {
        if (k == s) {
          ans = ti % 10;
          break;
        }
        s--, ti /= 10;
      }
      if (ans != -1) break;
    }
    cout << ans << '\n';
  }
  return 0;
}
