#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 1e5 + 5;
const int alp = 16;
ll a[maxn],pw[alp + 2],num[alp + 2],self_digit[alp + 2];
void prepare(int alp){
pw[0] = 1;
for (int i = 1 ; i <= alp ; i++){
pw[i] = pw[i - 1] * 10;
num[i] = pw[i] - pw[i - 1];
self_digit[i] = num[i] * i;
}
}
//get xth digit when laying 123456789101112131415
ll get_digit(ll x){
ll res = 0;
int digit = 0;
while (x >= self_digit[digit]){
x -= self_digit[digit];
digit++;
}
//x == 0, equals last digit, consequencely 9
if (!x) return 9;
ll n = (x - 1)/digit;
x -= digit * n;
n += pw[digit - 1];
vector <int> v;
while (n > 0){
v.push_back(n % 10);
n /= 10;
}
return v[v.size() - x];
}
ll sum_digit(ll x){
//sum digit 123..x
int digit = 0;
ll res = 0;
while (pw[digit] - 1 < x){
res += self_digit[digit];
digit++;
}
res += (x - pw[digit - 1] + 1) * (ll)digit;
return res;
}
//sum digits 1...x
int solve(ll a){
ll x = 1;
ll len = sum_digit(a);
while (4*x - 2 <= len) x = 4*x - 2;
return get_digit(x);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
prepare(alp);
vector <int> res;
int n;
cin >> n;
for (int i = 1 ; i <= n ; i++){
ll a;
cin >> a;
res.push_back(solve(a));
}
for (int x : res) cout << x;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBsZGIgbG9uZyBkb3VibGUKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIHN6YShhKSAoaW50KWEuc2l6ZSgpCiNkZWZpbmUgcGlyIHBhaXI8aW50LGludD4KI2RlZmluZSBwaXJsbCBwYWlyPGxsLGxsPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25z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