#include<iostream> 
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;

int cont = 10;

void Smethod(int a)
{
	if(cont == 0) return;
	int y[8];
	for(int i = 0; i < 8; i++)
	{
		y[i] = a % 10;
		a = floor(a / 10);
	}
	cout << y[5] << y[4] << y[3] << y[2] << endl;
	int b = y[5]*1000 + y[4]*100 + y[3]*10 + y[2];
	cont--;
	//printf(":%d:%d:",b,b*b);
	Smethod(b*b);
}

int main(){
	int n,a;
	cin >> n;

	for(int i = 0; i < n; i++)
	{
		cin >> a;
		Smethod(a*a);
		cont = 10;
	}
}