#include <bits/stdc++.h>
using namespace std;
long long total = 0;
int main() {
  long long x, q, k, t1, t;
  cin >> q;
  long long alfa[100002];
  alfa[1] = 1;
  for (t = 2; t < 10; t++) {
    alfa[t] = alfa[t - 1] + 1;
  }
  for (t = 10; t < 100; t++) {
    alfa[t] = alfa[t - 1] + 2;
  }
  for (t = 100; t < 1000; t++) {
    alfa[t] = alfa[t - 1] + 3;
  }
  for (t = 1000; t < 10000; t++) {
    alfa[t] = alfa[t - 1] + 4;
  }
  for (t = 10000; t < 22000; t++) {
    alfa[t] = alfa[t - 1] + 5;
  }
  string res;
  for (t = 1; t < 98075; t++) {
    res += to_string(t);
  }
  for (long long t = 0; t < q; t++) {
    x = 0;
    cin >> k;
    for (t1 = 0; t1 < k; t1 += alfa[x]) {
      x++;
    }
    t1 -= alfa[x];
    cout << res[k - t1 - 1] << endl;
  }
  return 0;
}
