#include <bits/stdc++.h>
using namespace std;
const int rl = 1e9;
long long getlen(int x) {
  long long len = 0;
  long long a = 1;
  long long n = x;
  while (n > 0) {
    len += n * (n + 1) / 2;
    a *= 10;
    n = x - a + 1;
  }
  return len;
}
long long getlen2(int n) {
  long long x = 10;
  long long r = 0;
  long long d = 1;
  while (x - (x / 10) < n) {
    r += (x - (x / 10)) * d;
    n -= x - (x / 10);
    x *= 10;
    d++;
  }
  r += n * d;
  return r;
}
string tostring(int x) {
  string s = "";
  while (x > 0) {
    s = (char)(48 + (x % 10)) + s;
    x /= 10;
  }
  return s;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long x;
    cin >> x;
    int l = 0, r = rl, sol;
    while (l <= r) {
      int mi = (l + r) / 2;
      if (getlen(mi) < x) {
        l = mi + 1;
        sol = mi;
      } else {
        r = mi - 1;
      }
    }
    x -= getlen(sol);
    l = 0;
    r = 1e9;
    while (l <= r) {
      int mi = (l + r) / 2;
      if (getlen2(mi) < x) {
        l = mi + 1;
        sol = mi;
      } else {
        r = mi - 1;
      }
    }
    x -= getlen2(sol);
    cout << tostring(sol + 1)[x - 1] << '\n';
  }
  return 0;
}
