#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = 1e6 + 6, mod = 998244353, M = 1e7 + 7;
const long long MAX = 5e18;
long long s, sum[N], q;
stack<int> t;
vector<int> S;
int dig(long long x) {
  int c = 0;
  while (x) {
    c++;
    t.push(x % 10);
    x /= 10;
  }
  while (!t.empty()) {
    S.push_back(t.top());
    t.pop();
  }
  return c;
}
int bs(int x) {
  int st = 0, en = N, mid;
  while (st < en) {
    mid = (st + en) >> 1;
    if (sum[mid] >= x)
      en = mid;
    else
      st = mid + 1;
  }
  return S[x - sum[st - 1]];
}
int main() {
  S.push_back(0);
  for (int i = 1; i < N; i++) {
    s += dig(i);
    sum[i] = sum[i - 1] + s;
  }
  cin >> q;
  while (q--) {
    cin >> s;
    cout << bs(s) << '\n';
  }
  return 0;
}
