#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <sstream>
int main()
{
int count;
std::vector<int> starts;
long tmp = 10;
long tmp2 = 0;
for (int i = 1; i < 18; i++)
{
starts.push_back(tmp2);
tmp2 += i * tmp;
tmp *= 10;
}
std::cin >> count;
while (count-- > 0)
{
long number;
std::cin >> number;
int pos;
for (pos = 0; pos < starts.size(); pos++)
{
if (starts[pos] > number)
{
pos--;
break;
}
}
number -= starts[pos];
long innum = number % (pos + 1);
long start = number / (pos + 1);
long num = start;
if (pos == 0)
num--;
std::ostringstream outs;
outs << num;
std::cout << outs.str()[innum] << std::endl;
}
return 0;
}