#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
long long k;
long long check(long long mid) {
  long long ans = 0, x = 1, y = 1;
  for (; y * 10 <= mid; y *= 10) {
    long long sum = y * 9;
    ans += x * (sum + 1) * sum / 2 + x * sum * (mid - y * 10 + 1);
    x++;
  }
  long long sum = mid - y + 1;
  return ans + x * sum * (sum + 1) / 2;
}
long long check1(long long mid) {
  long long x = 1, y = 1, ans = 0;
  for (; y * 10 <= mid; y *= 10) {
    ans += x * y * 9;
    x++;
  }
  return ans + x * (mid + 1 - y);
}
int f(int k, long long l) {
  long long m1 = l;
  int m = 0, x;
  while (m1) {
    m++;
    m1 /= 10;
  }
  m = m - k + 1;
  while (m--) {
    x = l % 10;
    l /= 10;
  }
  return x;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> k;
    long long l = 0, r = inf;
    while (l < r) {
      long long mid = (l + r + 1) >> 1;
      if (check(mid) >= k)
        r = mid - 1;
      else
        l = mid;
    }
    k -= check(l);
    l = 0;
    r++;
    while (l < r) {
      long long mid = (l + r + 1) >> 1;
      if (check1(mid) >= k)
        r = mid - 1;
      else
        l = mid;
    }
    k -= check1(l);
    l++;
    cout << f(k, l) << endl;
  }
  return 0;
}
