#include <bits/stdc++.h>
using namespace std;
int q;
long long check(int mid) {
  long long sum = 0;
  for (int i = 1; i <= mid; i *= 10)
    sum += 1ll * (mid - i + 1) * (mid - i + 2) / 2;
  return sum;
}
long long check2(int mid) {
  long long sum = 0;
  for (int i = 1; i <= mid; i *= 10) sum += 1ll * (mid - i + 1);
  return sum;
}
void Find(long long temp) {
  int l = 0, r = 1e9;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (check(mid) >= temp)
      r = mid;
    else
      l = mid;
  }
  temp -= check(l);
  l = 0, r++;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (check2(mid) >= temp)
      r = mid;
    else
      l = mid;
  }
  temp = check2(r) - temp;
  while (temp--) r /= 10;
  cout << r % 10 << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> q;
  while (q--) {
    long long x;
    cin >> x;
    Find(x);
  }
}
