#include "stdafx.h"
#include <stdint.h>
#include <iostream>
#include <vector>
using namespace std;
int calc(uint64_t i)
{
uint64_t digits = 1U;
uint64_t value = 1U;
uint64_t limit = 9U;
unsigned int tens;
i--;
while (i / limit >= digits) {
const uint64_t old_limit = limit;
i -= digits * limit;
digits++;
value *= 10U;
limit *= 10U;
if (limit <= old_limit)
break;
}
value += i / digits;
value /= pow(10,(digits - 1) - (i % digits));
return value % 10U;
}
int main()
{
vector<long long> queryvector = {};
long long int query;
cin >> query;
for (long int i = 0; i < query; i++)
{
long long int q;
cin >> q;
queryvector.push_back(q);
}
for (long long kysely : queryvector)
{
cout << calc(kysely) << endl;
}
main();
}