#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdlib>
using namespace std;
typedef long long ll;
ll
decade(ll n, ll *sum)
{
*sum = 0;
for (int i = 1; i < 1000000; i++) {
if (*sum + i*9*pow(10.0, i-1) > n)
return i;
else
*sum += i*9*pow(10.0, i-1);
}
return 0;
}
ll
nnum(ll dec, ll nth)
{
return (ll)(pow(10.0, (int)dec-1)-1+nth);
}
int dig(int a, int b) {
return (int)(a / pow(10.0, b)) % 10;
}
int
main(int argc, char **argv)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
ll qs[q];
for (int i = 0; i < q; i++) {
cin >> qs[i];
if (qs[i] < 10) {
cout << qs[i] << "\n";
} else {
ll inth, nth, dec, s, sm, num;
dec = decade(qs[i], &s);
sm = qs[i] - s;
nth = (ll)ceil((double)sm/(double)dec);
num = nnum(dec, nth);
inth = (sm-1) % dec+1-dec;
char thing [1000000];
sprintf(thing, "%d", num);
cout << thing[inth] << "\n";
}
}
return 0;
}