#include <bits/stdc++.h>
using namespace std;
long long checklen(long long k) {
  long long ans = 0;
  long long p10 = 1;
  long long dig = 1;
  while (p10 <= k) {
    long long num = min(9 * p10, k - p10 + 1);
    ans += (k + 1) * num * dig;
    ans -= (num + 2 * p10 - 1) * num / 2 * dig;
    dig++;
    p10 = p10 * 10;
  }
  return ans;
}
long long singlelen(long long k) {
  long long ans = 0;
  long long p10 = 1;
  long long dig = 1;
  while (p10 <= k) {
    long long num = min(9 * p10, k - p10 + 1);
    ans += num * dig;
    dig++;
    p10 = p10 * 10;
  }
  return ans;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int q;
  cin >> q;
  while (q--) {
    long long x;
    cin >> x;
    long long lo = 0, hi = 2e9;
    while (lo <= hi) {
      long long mid = (lo + hi) / 2;
      if (checklen(mid) >= x) {
        hi = mid - 1;
      } else {
        lo = mid + 1;
      }
    }
    long long offset = checklen(hi);
    lo = 0, hi = 2e9;
    while (lo <= hi) {
      long long mid = (lo + hi) / 2;
      if (singlelen(mid) >= x - offset) {
        hi = mid - 1;
      } else {
        lo = mid + 1;
      }
    }
    long long offset2 = singlelen(hi);
    long long num = hi + 1;
    string s = to_string(num);
    cout << s[x - offset - offset2 - 1] << "\n";
  }
}
