#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 5, mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  {
    long long dig[10] = {}, tot[10] = {};
    dig[1] = 9;
    for (long long i = 2; i <= 9; i++) dig[i] = dig[i - 1] * 10;
    for (long long i = 1; i <= 9; i++) {
      tot[i] = dig[i] * i;
      tot[i] += tot[i - 1];
    }
    for (long long i = 1; i <= 9; i++) {
      dig[i] = i * (dig[i] * (dig[i] + 1) / 2) + tot[i - 1] * dig[i];
    }
    for (long long i = 1; i <= 9; i++) dig[i] += dig[i - 1];
    long long q;
    cin >> q;
    while (q--) {
      long long k;
      cin >> k;
      long long dig_num;
      for (long long i = 1; i <= 9; i++) {
        if (dig[i] >= k) {
          dig_num = i;
          break;
        }
      }
      long long start = pow(10, dig_num - 1);
      long long lo = start, hi = (long long)pow(10, dig_num) - 1, ans = lo;
      k -= dig[dig_num - 1];
      while (lo <= hi) {
        long long mid = lo + (hi - lo) / 2;
        long long diff = mid - start;
        long long total =
            (diff * (diff + 1) / 2) * dig_num + diff * tot[dig_num - 1];
        if (total < k) {
          ans = mid;
          lo = mid + 1;
        } else
          hi = mid - 1;
      }
      long long diff = ans - start;
      long long total =
          (diff * (diff + 1) / 2) * dig_num + diff * tot[dig_num - 1];
      k -= total;
      for (long long i = 1; i <= 9; i++) {
        if (tot[i] >= k) {
          k -= tot[i - 1];
          dig_num = i;
          break;
        }
      }
      long long cal = k / dig_num;
      if (k % dig_num == 0) cal--;
      k -= cal * dig_num;
      cal = cal + (long long)pow(10, dig_num - 1);
      vector<long long> v;
      while (cal) {
        v.push_back(cal % 10);
        cal /= 10;
      }
      reverse(v.begin(), v.end());
      cout << v[k - 1] << "\n";
    }
  }
  return 0;
}
