#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;
long long p[20];
long long getSize(long long x) {
  long long sz = 0;
  while (x > 0) {
    sz++;
    x /= 10;
  }
  return sz;
}
long long count(long long x) {
  long long res = 0;
  long long sz = getSize(x);
  for (long long i = 1; i <= sz; i++) {
    long long l = p[i - 1] - 1;
    long long r = min(p[i] - 2, x - 1);
    res += i * (2 * x - r - l) * (r - l + 1) / 2;
  }
  return res;
}
long long count2(long long x) {
  long long res = 0;
  long long sz = getSize(x);
  long long c = 9;
  for (long long i = 1; i < sz; i++) {
    res += i * c;
    c *= 10;
  }
  c = p[sz - 1] - 1;
  res += sz * (x - c);
  return res;
}
void solve() {
  long long k;
  cin >> k;
  long long l = 1, r = min(k, (long long)200000000), res = 0, m;
  while (l <= r) {
    m = (l + r) / 2;
    if (count(m) < k) {
      l = m + 1;
    } else {
      res = m;
      r = m - 1;
    }
  }
  long long x = k - count(res - 1);
  l = 1, r = res, res = 0, m;
  while (l <= r) {
    m = (l + r) / 2;
    if (count2(m) < x) {
      l = m + 1;
    } else {
      res = m;
      r = m - 1;
    }
  }
  x = x - count2(res - 1);
  string s = to_string(res);
  cout << s[x - 1] << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  p[0] = 1;
  for (int i = 1; i < 20; i++) p[i] = p[i - 1] * 10;
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
