#include <bits/stdc++.h>
using namespace std;
long long a[1000000], b[1000000];
void yiwuwuyi() {
  long long tmp = 0;
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= 1000000; i++) {
    if (i <= 9 && i >= 1) {
      tmp += 1;
    }
    if (i <= 99 && i >= 10) {
      tmp += 2;
    }
    if (i <= 999 && i >= 100) {
      tmp += 3;
    }
    if (i <= 9999 && i >= 1000) {
      tmp += 4;
    }
    if (i <= 99999 && i >= 10000) {
      tmp += 5;
    }
    a[i] = a[i - 1] + tmp;
  }
  tmp = 0;
  for (int i = 1; i <= 54000; i++) {
    if (i <= 9 && i >= 1) {
      tmp += 1;
    }
    if (i <= 99 && i >= 10) {
      tmp += 2;
    }
    if (i <= 999 && i >= 100) {
      tmp += 3;
    }
    if (i <= 9999 && i >= 1000) {
      tmp += 4;
    }
    if (i <= 99999 && i >= 10000) {
      tmp += 5;
    }
    b[i] = tmp;
  }
}
int main() {
  yiwuwuyi();
  int n;
  cin >> n;
  long long x;
  while (n--) {
    cin >> x;
    int l = 1, r = 22000;
    long long pos1, pos2;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (a[mid] <= x) {
        l = mid + 1;
        pos1 = mid;
      } else
        r = mid - 1;
    }
    x -= a[pos1];
    if (x == 0) {
      cout << pos1 % 10 << endl;
      continue;
    } else {
      int l = 1, r = 22000, fin;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (b[mid] <= x) {
          l = mid + 1;
          pos2 = mid;
        } else
          r = mid - 1;
      }
      x -= b[pos2];
      if (x == 0) {
        cout << pos2 % 10 << endl;
        continue;
      } else {
        pos2 += 1;
        vector<int> v;
        v.clear();
        while (pos2 > 0) {
          v.push_back(pos2 % 10);
          pos2 /= 10;
        }
        cout << v[v.size() - x] << endl;
      }
    }
  }
}
