#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
template <typename Head>
void dump_1(const char* str, Head&& h) {
  cerr << str << ": " << h << '\n';
}
template <typename Head, typename... Tail>
void dump_1(const char* str, Head&& h, Tail&&... t) {
  while (*str != ',') {
    cerr << *str++;
  }
  cerr << ": " << h << ' ';
  dump_1(str + 1, t...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << '(' << v.first << ", " << v.second << ')';
  return os;
}
template <typename T1, typename T2, typename T3>
ostream& operator<<(ostream& os, const tuple<T1, T2, T3>& v) {
  os << '(' << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ')';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ' ';
    }
    os << *it;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ' ';
    }
    os << *it;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ' ';
    }
    os << *it;
  }
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& v) {
  os << '{';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) {
      os << ", ";
    }
    os << it->first << ':' << it->second;
  }
  os << '}';
  return os;
}
void Yes(void) { cout << "Yes" << '\n'; }
void No(void) { cout << "No" << '\n'; }
void YES(void) { cout << "YES" << '\n'; }
void NO(void) { cout << "NO" << '\n'; }
template <typename T>
void chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
  }
}
template <typename T>
void chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
  }
}
template <typename T>
void vin(vector<T>& v, ll len) {
  for (ll i = 0; i < (len); i++) {
    cin >> v[i];
  }
}
template <typename Head>
void in_1(Head& h) {
  cin >> h;
}
template <typename Head, typename... Tail>
void in_1(Head& h, Tail&... t) {
  cin >> h;
  in_1(t...);
}
template <typename Head>
void print_1(Head&& h) {
  cout << h << '\n';
}
template <typename Head, typename... Tail>
void print_1(Head&& h, Tail&&... t) {
  cout << h << ' ';
  print_1(t...);
}
ll f(ll n) {
  if (n <= 9) {
    return n;
  }
  ll keta = 1;
  for (ll i = 100; i <= 1e18; i *= 10) {
    ll i9 = i - 1;
    ++keta;
    if (n <= i9) {
      ll i0 = i / 10 - 1;
      return f(i0) + (n - i0) * keta;
    }
  }
  return 0;
}
ll calc(ll n) {
  if (n <= 9) {
    ll a = 1;
    ll d = 1;
    return (a + a + (n - 1) * d) * n / 2;
  }
  ll keta = 1;
  for (ll i = 100; i <= 1e18; i *= 10) {
    ll i9 = i - 1;
    ++keta;
    if (n <= i9) {
      ll i0 = i / 10 - 1;
      ll a = f(i0) + keta;
      ll d = keta;
      n -= i0;
      return calc(i0) + (a + a + (n - 1) * d) * n / 2;
    }
  }
  return 0;
}
string f2(ll n) {
  ll max1 = 10;
  ll keta = 2;
  while (n >= f(max1 - 1)) {
    max1 *= 10;
    keta++;
  }
  keta--;
  if (keta == 1) {
    return to_string(n + 1);
  }
  max1 /= 10;
  n -= f(max1 - 1);
  ll a = max1 + n / keta;
  return to_string(a).substr(n % keta, 1);
}
void solve() {
  ll Q;
  in_1(Q);
  for (ll q = 0; q < (Q); q++) {
    ll x;
    in_1(x);
    if (x == 1) {
      print_1(1);
      continue;
    }
    ll lo = 1;
    ll hi = 1000000000000;
    ll val = 0;
    while (hi - lo > 1) {
      ll mi = lo + (hi - lo) / 2;
      val = calc(mi);
      if (val > x) {
        hi = mi;
      } else {
        lo = mi;
      }
    }
    val = calc(lo);
    if (x == val) {
      string s = to_string(lo);
      print_1(s.substr(s.length() - 1, 1));
    } else {
      print_1(f2(x - val - 1));
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  solve();
}
