#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long sum2[100], sum3[1000], sum4[10000], sum5[100000], ed;
long long cnt[100005];
int ans[] = {0, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5,
             1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3,
             4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9};
void prework() {
  long long st;
  st = 9;
  for (int i = 1; i <= 90; i++) sum2[i] = sum2[i - 1] + (st + 2 * i);
  st = 189;
  for (int i = 1; i <= 900; i++) sum3[i] = sum3[i - 1] + (st + 3 * i);
  st = 2889;
  for (int i = 1; i <= 9000; i++) sum4[i] = sum4[i - 1] + (st + 4 * i);
  st = 38889;
  for (int i = 1; i <= 90000; i++) {
    sum5[i] = sum5[i - 1] + (st + 5 * i);
    if (sum5[i] > 1000000000) {
      ed = i;
      break;
    }
  }
  for (int i = 1; i <= 100000; i++) {
    if (i >= 1 && i < 10)
      cnt[i] = cnt[i - 1] + 1;
    else if (i >= 10 && i < 100)
      cnt[i] = cnt[i - 1] + 2;
    else if (i >= 100 && i < 1000)
      cnt[i] = cnt[i - 1] + 3;
    else if (i >= 1000 && i < 10000)
      cnt[i] = cnt[i - 1] + 4;
    else if (i >= 10000 && i < 100000)
      cnt[i] = cnt[i - 1] + 5;
  }
}
int te[12], tot;
int getnum(int num, int k) {
  tot = 0;
  while (num) {
    te[++tot] = num % 10;
    num /= 10;
  }
  return te[tot - k + 1];
}
int dfs(long long k) {
  if (k <= 45) {
    return ans[k];
  } else if (k > 45 && k <= 9045) {
    k -= 45;
    int pos = upper_bound(sum2 + 1, sum2 + 91, k) - sum2;
    k -= sum2[pos - 1];
    if (k == 0)
      return (pos - 1 + 9) % 10;
    else {
      int sb = upper_bound(cnt + 1, cnt + 1 + 100000, k) - cnt;
      k -= cnt[sb - 1];
      if (k == 0) return (sb - 1) % 10;
      return getnum(sb, k);
    }
  } else if (k > 9045 && k <= 1395495) {
    k -= 9045;
    int pos = upper_bound(sum3 + 1, sum3 + 901, k) - sum3;
    k -= sum3[pos - 1];
    if (k == 0)
      return (pos - 1 + 99) % 10;
    else {
      int sb = upper_bound(cnt + 1, cnt + 1 + 100000, k) - cnt;
      k -= cnt[sb - 1];
      if (k == 0) return (sb - 1) % 10;
      return getnum(sb, k);
    }
  } else if (k > 1395495 && k <= 189414495) {
    k -= 1395495;
    int pos = upper_bound(sum4 + 1, sum4 + 9001, k) - sum4;
    k -= sum4[pos - 1];
    if (k == 0)
      return (pos - 1 + 999) % 10;
    else {
      int sb = upper_bound(cnt + 1, cnt + 1 + 100000, k) - cnt;
      k -= cnt[sb - 1];
      if (k == 0) return (sb - 1) % 10;
      return getnum(sb, k);
    }
  } else if (k > 189414495) {
    k -= 189414495;
    int pos = upper_bound(sum5 + 1, sum5 + ed + 1, k) - sum5;
    k -= sum5[pos - 1];
    if (k == 0)
      return (pos - 1 + 9999) % 10;
    else {
      int sb = upper_bound(cnt + 1, cnt + 1 + 100000, k) - cnt;
      k -= cnt[sb - 1];
      if (k == 0) return (sb - 1) % 10;
      return getnum(sb, k);
    }
  }
}
int main() {
  prework();
  int n, k;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &k);
    printf("%d\n", dfs(k));
  }
  return 0;
}
