#include <bits/stdc++.h>
using namespace std;
long long base[10], base2[10], c1[10], c2[10], c3[10];
int main() {
  base[1] = base2[1] = 9, base2[0] = -1;
  for (register int i = 2; i <= 9; i++)
    base[i] = base[i - 1] * 10, base2[i] = base2[i - 1] + base[i];
  c1[1] = 9;
  for (register int i = 2; i <= 9; i++) c1[i] = c1[i - 1] + i * base[i];
  c2[1] = 45;
  for (register int i = 2; i <= 9; i++)
    c2[i] = c2[i - 1] + base[i] * (2 * c1[i - 1] + i + base[i] * i) / 2;
  for (register int i = 1; i <= 9; i++) c3[i] = i * base[i];
  int T;
  scanf("%d", &T);
  while (T--) {
    long long k;
    scanf("%lld", &k);
    long long l = 0, r = 9, mid, ans, ans2;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (k > c2[mid])
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    k -= c2[ans];
    long long t1 = 2 * c1[ans], t2 = ans + 1;
    l = 0, r = base[ans + 1];
    while (l <= r) {
      mid = (l + r) >> 1;
      if (k > (t1 + (mid + 1) * t2) * mid / 2)
        l = mid + 1, ans2 = mid;
      else
        r = mid - 1;
    }
    k -= (t1 + (ans2 + 1) * t2) * ans2 / 2;
    int ed = ans2 + base2[ans] + 1;
    int pos = 1;
    while (k > c3[pos]) k -= c3[pos++];
    base2[0] = 0;
    long long t = (k - 1) / pos + 1 + base2[pos - 1];
    vector<int> rec;
    while (t) rec.push_back(t % 10), t /= 10;
    k = k % pos == 0 ? pos : k % pos;
    for (register int i = pos - 1; i >= 0; i--)
      if (--k == 0) {
        printf("%d\n", rec[i]);
        break;
      }
  }
  return 0;
}
