#include "stdio.h"
int main()
{
int m,n;
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
if(n<=10&&n>1000000)
return 0;
if(n>10&&n<100)
n%=10;
else if(n<1000)
n%=100;
else if(n<10000)
n%=1000;
else if(n<100000)
n%=10000;
else if(n<=1000000)
n%=100000;
printf("%d\n",n);}
return 0;
}