#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
const int INF = 1e9;
const int M = 1000000007;
void solve2(long long n) {
  string str = "";
  long long start = 1;
  while (str.size() <= n) {
    str += to_string(start);
    start++;
  }
  cout << str[n - 1];
}
void solve(long long int n) {
  if (n < 10) {
    cout << n;
    return;
  }
  n++;
  long long int multi = 100;
  long long digit = 2;
  n -= 10;
  long long start = 10;
  while (n > 0) {
    long long term = (multi - start) * digit;
    if (term == n) {
      cout << 9;
      break;
    } else if (n > term) {
      n -= term;
      start = multi;
      multi *= 10LL;
      digit++;
    } else {
      long long pos = (n - 1LL) / digit;
      long long rem = n % digit;
      long long num = start + pos;
      string res = to_string(num);
      if (rem == 0) {
        cout << res[res.size() - 1];
        break;
      } else {
        cout << res[rem - 1];
        break;
      }
    }
  }
  return;
}
long long calculate(long long init) {
  long long n = init;
  if (n < 10) {
    return n;
  }
  n -= 9;
  long long ct = 9;
  long long digit = 2;
  long long multi = 100;
  long long start = 10;
  while (n > 0) {
    long long terms = (multi - start) * digit;
    long long dif = multi - start;
    if (dif == n) {
      ct += terms;
      n -= dif;
    } else if (dif > n) {
      ct += (n * digit);
      n = 0;
    } else {
      ct += terms;
      n -= dif;
    }
    multi *= 10LL;
    start *= 10LL;
    digit++;
  }
  return ct;
}
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long init = 1;
    while (n > 0) {
      long long c = calculate(init);
      if (n > c) {
        n -= c;
        init++;
        continue;
      } else {
        solve(n);
        cout << "\n";
        ;
        break;
      }
    }
  }
  return 0;
}
