#include <bits/stdc++.h>
using namespace std;
unsigned long long len[10];
unsigned long long s[10];
unsigned long long pos[10];
unsigned long long f(unsigned long long m, unsigned long long d) {
  return m * len[d - 1] + d * (((m + 1) * m) / 2);
}
int main() {
  int q = 0;
  len[0] = 0;
  s[0] = 0;
  pos[0] = 0;
  unsigned long long pow = 1;
  for (int i = 1; i < 10; ++i) {
    len[i] = len[i - 1] + i * 9 * pow;
    s[i] = len[i - 1] * 9 * pow + (i * (9 * pow + 1) * 9 * pow) / 2;
    pos[i] = pos[i - 1] + s[i];
    pow *= 10;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    unsigned long long k;
    cin >> k;
    unsigned long long d;
    for (int j = 0; j < 9; ++j) {
      if (pos[j] < k && k <= pos[j + 1]) {
        k -= pos[j];
        d = j + 1;
        break;
      }
    }
    unsigned long long l = 0;
    unsigned long long r = 2e10;
    while (true) {
      unsigned long long m = (l + r) / 2;
      unsigned long long fl = f(m - 1, d);
      unsigned long long fr = f(m, d);
      if (k <= fl) {
        r = m;
      } else if (k > fr) {
        l = m;
      } else {
        k -= fl;
        break;
      }
    }
    for (int j = 0; j < 9; ++j) {
      if (len[j] < k && k <= len[j + 1]) {
        k -= len[j];
        d = j + 1;
        break;
      }
    }
    unsigned long long pw = 1;
    for (int i = 1; i < d; ++i) {
      pw *= 10;
    }
    --k;
    pw += (k / d);
    cout << to_string(pw)[k % d] << endl;
  }
}
