#include <bits/stdc++.h>
using namespace std;
long long k;
bool comp(int a, int b) { return a < b; }
long long cant(long long x) {
  long long div = 1;
  long long suma = 0;
  for (; div <= 10000000000; div *= 10) {
    if (x < div) break;
    suma += ((x - div + 1) * (x - div + 2)) / 2;
  }
  return suma;
}
long long cant2(long long x) {
  long long div = 1;
  long long suma = 0;
  long long i = 1;
  for (; div <= 1000000000; div *= 10) {
    if (div * 10 > x) break;
    suma += ((div * 10 - div) * i);
    i++;
  }
  suma += ((x - (div - 1)) * i);
  return suma;
}
bool ok(long long x) {
  if (cant(x) >= k) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> k;
    if (k == 1) {
      cout << 1 << "\n";
      continue;
    }
    long long ini = 1, fin = 1000000000, mid = (ini + fin) / 2;
    long long num;
    while (fin >= ini) {
      mid = (ini + fin) / 2;
      if (ok(mid))
        fin = mid - 1;
      else
        ini = mid + 1;
    }
    if (ok(mid - 1))
      num = mid - 1;
    else if (ok(mid))
      num = mid;
    else
      num = mid + 1;
    long long c = cant(num - 1);
    ini = 1, fin = num, mid = (ini + fin) / 2;
    while (fin >= ini) {
      mid = (ini + fin) / 2;
      if (cant2(mid) + c >= k)
        fin = mid - 1;
      else
        ini = mid + 1;
    }
    if (cant2(mid - 1) + c >= k)
      num = mid - 1;
    else if (cant2(mid) + c >= k)
      num = mid;
    else
      num = mid + 1;
    long long x = cant2(num) + c;
    long long div = 1;
    while (1) {
      if (x == k) break;
      div *= 10;
      x--;
    }
    cout << (num / div) % 10 << "\n";
  }
  return 0;
}
