#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long sum[maxn];
long long num[maxn];
int Solve(int x, int t) {
  int num[10];
  int cnt = 1;
  while (1) {
    if (x) {
      num[cnt++] = x % 10;
      x /= 10;
    } else
      break;
  }
  return num[cnt - t];
}
int solve(int x) {
  int cnt = 0;
  while (1) {
    if (x) {
      x /= 10;
      cnt++;
    } else
      break;
  }
  return cnt;
}
int t;
int main() {
  int ans = 0;
  for (int i = 1; i <= 1e5; i++) {
    num[i] = solve(i);
    ans += num[i];
    if (sum[i] >= 1e9)
      break;
    else
      sum[i] = sum[i - 1] + ans;
  }
  cin >> t;
  while (t--) {
    int id;
    cin >> id;
    int j = lower_bound(sum, sum + maxn, id) - sum;
    if (id != sum[j]) {
      id -= sum[j - 1];
      for (int i = 1; i <= maxn; i++) {
        if (id - num[i] > 0)
          id -= num[i];
        else {
          if (id == 0) {
            cout << (i - 1) % 10 << endl;
            break;
          } else {
            cout << Solve(i, id) << endl;
            break;
          }
        }
      }
    } else
      cout << j % 10 << endl;
  }
}
