#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 2e9 + 10;
int a[N], b[N] = {0}, c[N] = {0};
int main(void) {
  int R = 32000, tot = 0;
  for (int i = 1; i <= R; i++) {
    if (i >= 1 && i <= 9)
      a[i] = i;
    else if (10 <= i && i <= 99)
      a[i] = 9 + 2 * (i - 9);
    else if (100 <= i && i <= 999)
      a[i] = 189 + 3 * (i - 99);
    else if (1000 <= i && i <= 9999)
      a[i] = 2889 + 4 * (i - 999);
    else if (10000 <= i && i <= R)
      a[i] = 38889 + 5 * (i - 9999);
    b[i] = b[i - 1] + a[i];
    if (b[i] >= inf) {
      tot = i;
      break;
    }
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    int k;
    scanf("%d", &k);
    int pos = upper_bound(b + 1, b + tot + 1, k) - b;
    if (k == b[pos - 1]) {
      printf("%d\n", (pos - 1) % 10);
    } else {
      int x = k - b[pos - 1], y = 0, ans;
      string ss = "";
      for (int i = 1; i <= pos; i++) {
        if (i >= 1 && i <= 9) {
          y++;
          c[y] = i;
          if (y == x) {
            ans = c[y];
            break;
          }
        } else if (i >= 10 && i <= 99) {
          y++;
          c[y] = i / 10;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 10;
          if (y == x) {
            ans = c[y];
            break;
          }
        } else if (i >= 100 && i <= 999) {
          y++;
          c[y] = i / 100;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 100 / 10;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 10;
          if (y == x) {
            ans = c[y];
            break;
          }
        } else if (i >= 1000 && i <= 9999) {
          y++;
          c[y] = i / 1000;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 1000 / 100;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 100 / 10;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 10;
          if (y == x) {
            ans = c[y];
            break;
          }
        } else {
          y++;
          c[y] = i / 10000;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 10000 / 1000;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 1000 / 100;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 100 / 10;
          if (y == x) {
            ans = c[y];
            break;
          }
          y++;
          c[y] = i % 10;
          if (y == x) {
            ans = c[y];
            break;
          }
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
