CSES - Shared codeLink to this code: https://cses.fi/paste/62e169b7b0d1f9ef398110/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vi vector<int>
#define pi pair<int, int>
#define vs vector<string>
#define all(c) (c).begin(), (c).end()
#define F first
#define S second

const int KM = 1e18;
int q, k;

vi a;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> q;
    a.push_back(0);
    a.push_back(9);

    while (true)
    {
        int num = (a.back() / (a.size() - 1)) * 10 * a.size();
        a.push_back(num);
        if (num > KM)
            break;
    }

    for (int i = 1; i < a.size(); i++)
        a[i] += a[i - 1];

    while (q--)
    {
        cin >> k;
        int i = lower_bound(all(a), k) - a.begin();
        k -= a[i - 1];

        int pbln = 0, pbs = i - 1;
        while (pbs--)
            pbln = (pbln * 10) + 9;

        int ofs = k / i, pos = k % i;
        if (pos == 0)
            cout << (ofs + pbln) % 10;
        else
        {
            int dec = i - pos;
            ofs++;
            ofs += pbln;
            while (dec--)
                ofs /= 10;
            cout << ofs % 10;
        }

        cout << '\n';
    }

    return 0;
}