#include <bits/stdc++.h>
using namespace std;
long long cal1(long long x) {
  long long ub = 10;
  long long lb = 1;
  long long low = 0;
  long long del = 1;
  long long ret = 0;
  while (ub - 1 <= x) {
    ret += (ub - lb) * (low * 2 + del * (ub - lb + 1)) / 2;
    low += (ub - lb) * del;
    del++;
    ub *= 10;
    lb *= 10;
  }
  ret += (x - lb + 1) * (low * 2 + del * (x - lb + 2)) / 2;
  return ret;
}
int cal2(long long x) {
  long long low = 1;
  long long num = 9;
  long long sig = 1;
  while (x > sig * num) {
    x -= sig * num;
    num *= 10;
    sig++;
    low *= 10;
  }
  low += (x - 1) / sig;
  x = (x - 1) % sig + 1;
  vector<int> v;
  while (low) {
    v.push_back(low % 10);
    low /= 10;
  }
  reverse(v.begin(), v.end());
  return v[x - 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    int now = 0;
    for (int i = 1 << 29; i; i >>= 1) {
      int cur = now + i;
      if (cal1(cur) < x) {
        now = cur;
      }
    }
    x -= cal1(now);
    now++;
    cout << cal2(x) << '\n';
  }
}
