#include <bits/stdc++.h>
using namespace std;
long long _9[100];
long long solve(long long n, long long i) {
  long long now = _9[i] / 9;
  n--;
  now += (n / i);
  n %= i;
  char s[100];
  sprintf(s, "%lld", now);
  return s[n] - (long long)'0';
}
long long solve2(long long n) {
  if (n <= 9) return n;
  long long ans = 0;
  int i;
  for (i = 1;; i++) {
    if (_9[i] * i >= (n - ans)) break;
    ans += _9[i] * i;
  }
  n -= ans;
  return solve(n, i);
}
long long solve3(long long n) {
  if (n <= 9)
    return n * (n + 1) / 2;
  else if (n <= 99) {
    long long ans = 0;
    ans += solve3(9);
    n -= 9;
    ans += 9 * n;
    ans += 2 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 999) {
    long long ans = 0;
    ans += solve3(99);
    long long c = ans - solve3(98);
    n -= 99;
    ans += c * n;
    ans += 3 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 9999) {
    long long ans = 0;
    ans += solve3(999);
    long long c = ans - solve3(998);
    n -= 999;
    ans += c * n;
    ans += 4 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 99999) {
    long long ans = 0;
    ans += solve3(9999);
    long long c = ans - solve3(9998);
    n -= 9999;
    ans += c * n;
    ans += 5 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 999999) {
    long long ans = 0;
    ans += solve3(99999);
    long long c = ans - solve3(99998);
    n -= 99999;
    ans += c * n;
    ans += 6 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 9999999) {
    long long ans = 0;
    ans += solve3(999999);
    long long c = ans - solve3(999998);
    n -= 999999;
    ans += c * n;
    ans += 7 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 99999999) {
    long long ans = 0;
    ans += solve3(9999999);
    long long c = ans - solve3(9999998);
    n -= 9999999;
    ans += c * n;
    ans += 8 * n * (n + 1) / 2;
    return ans;
  } else if (n <= 999999999) {
    long long ans = 0;
    ans += solve3(99999999);
    long long c = ans - solve3(99999998);
    n -= 99999999;
    ans += c * n;
    ans += 9 * n * (n + 1) / 2;
    return ans;
  }
}
int main() {
  _9[1] = 9;
  for (int i = 2; i <= 18; i++) _9[i] = _9[i - 1] * 10;
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long x1 = 0, x2 = 499999999, x;
    while (x1 + 1 != x2) {
      x = (x1 + x2) / 2;
      if (solve3(x) >= n)
        x2 = x;
      else
        x1 = x;
    }
    n -= solve3(x1);
    cout << solve2(n) << endl;
  }
  return 0;
}
