#include <bits/stdc++.h>
using namespace std;
long long int Lpow(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2) ans = (ans * a);
    a = (a * a);
    b = b / 2;
  }
  return ans;
}
long long int fun(long long int mid) {
  long long int temp = 100000000;
  long long int dig = 9;
  while (temp > mid) temp = temp / 10, dig--;
  long long int ans = ((mid - temp + 1) * (mid - temp + 2)) / 2 * dig;
  long long int sum = ((mid - temp + 1));
  temp = temp / 10;
  temp = temp * 9;
  dig--;
  while (dig > 0) {
    ans = ans + (sum * temp + (temp * (temp + 1)) / 2) * dig;
    sum = sum + temp;
    temp = temp / 10;
    dig--;
  }
  return ans;
}
long long int fun2(long long int mid) {
  if (mid == 0) return 0ll;
  long long int temp = 100000000;
  long long int dig = 9;
  while (temp > mid) temp = temp / 10, dig--;
  long long int ans = (mid - temp + 1) * dig;
  temp /= 10;
  temp *= 9;
  dig--;
  while (dig > 0) {
    ans += temp * dig;
    dig--;
    temp /= 10;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int k;
    cin >> k;
    if (k == 1) {
      cout << 1 << endl;
      continue;
    }
    long long int l = 1;
    long long int r = 500000001;
    long long int store = 0;
    while (l < r) {
      long long int mid = (l + r + 1) / 2;
      long long int ans = fun(mid);
      if (ans < k)
        l = mid;
      else
        r = mid - 1;
    }
    long long int to_find = k - fun(l);
    r = l + 1;
    l = 0;
    while (l < r) {
      long long int mid = (l + r + 1) / 2;
      long long int ans = fun2(mid);
      if (ans < to_find)
        l = mid;
      else
        r = mid - 1;
    }
    to_find = to_find - fun2(l);
    string last = to_string(l + 1);
    cout << last[to_find - 1] << endl;
  }
  return 0;
}
