#include <stdio.h>
int rand(int s);
int main(){
	 int i,s,j=1,n;
	 int a[8];
	 scanf("%d",&n);
	 while(n--){
		 scanf("%d",&s);
		 for(i=0;i<10;i++) s = rand(s);
		 printf("%d\n",s);
	 }

	 return 0;
}

int rand(int s){
	int i,r=0,j=0;
	s *= s;s /= 100;
	for(i=1;i<1001;i*=10){
		r += (s%10)*i;
		j++;
		s /= 10;
	}
	return r;
}
			