#include <bits/stdc++.h>
using namespace std;
const long long UP = 1000000000;
int numD(long long n) {
  int sum = 0;
  while (n) {
    sum++;
    n /= 10;
  }
  return sum;
}
long long nines(int n) {
  if (n == 0) return 0;
  vector<char> T(n, '9');
  return stoll(string(T.begin(), T.end()));
}
long long seqO1(long long n) {
  long long num = 0;
  int numd = numD(n);
  for (int i = numd; i > 0; i--) {
    long long t;
    if (i == numd)
      t = n - nines(i - 1);
    else
      t = n - nines(i - 1);
    num += (t * t + t) / 2;
  }
  return num;
}
long long ans;
long long t;
void binS(long long lower, long long upper) {
  if (lower > upper) return;
  long long mid = (upper - lower) / 2 + lower;
  if (seqO1(mid) < t) {
    ans = mid;
    binS(mid + 1, upper);
  } else
    binS(lower, mid - 1);
}
char locate(long long n) {
  long long digits = 0;
  int cnt;
  for (cnt = 1;; cnt++) {
    long long addi = cnt * (nines(cnt) - nines(cnt - 1));
    if (digits + addi < n)
      digits += addi;
    else {
      n -= digits;
      break;
    }
  }
  cnt--;
  long long y = nines(cnt);
  cnt++;
  y += n / cnt;
  long long temp = n % cnt;
  if (n % cnt) {
    y++;
    return to_string(y)[n % cnt - 1];
  } else {
    string s = to_string(y);
    return s[s.length() - 1];
  }
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    cin >> t;
    binS(0, UP);
    long long t2 = t - seqO1(ans);
    cout << locate(t2) << '\n';
  }
}
