시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 47 22 17 47.222%

문제

1, 3, 7, 9로 끝나는 숫자 S가 주어진다. 이때, 세제곱했을 때, S로 끝나는 수가 반드시 존재한다.

예를들어, S가 123이면, 947을 세제곱하면 849278123이 되고, 이 수는 123으로 끝난다.

S가 주어졌을 때, 세제곱했을 때 S로 끝나는 숫자를 찾아 출력하는 프로그램을 작성하시오. 이때 x의 길이는 S의 길이보다 작거나 같아야 한다.

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다. 둘째 줄 부터 T개 줄에는 테스트 케이스의 정보가 주어진다. 각 테스트 케이스는 숫자 하나로 이루어져 있고, 이 수는 문제에서 설명한 S이다. S는 1, 3, 7, 9로 끝나며, 최대 10자리이다.

출력

각 테스트 케이스에 대해 한 줄에 하나씩 세제곱햇을 때 S가 되는 수 x를 출력한다.

예제 입력 1

4
123
1234567
435621
9876543213

예제 출력 1

947
2835223
786941
2916344917
W3sicHJvYmxlbV9pZCI6IjI3MzEiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiIxMzc5XHVjNjQwIFx1YzEzOFx1YzgxY1x1YWNmMSIsImRlc2NyaXB0aW9uIjoiPHA+XHJcblx0MSwgMywgNywgOVx1Yjg1YyBcdWIwNWRcdWIwOThcdWIyOTQgXHVjMjJiXHVjNzkwIFNcdWFjMDAgXHVjOGZjXHVjNWI0XHVjOWM0XHViMmU0LiBcdWM3NzRcdWI1NGMsIFx1YzEzOFx1YzgxY1x1YWNmMVx1ZDU4OFx1Yzc0NCBcdWI1NGMsIFNcdWI4NWMgXHViMDVkXHViMDk4XHViMjk0IFx1YzIxOFx1YWMwMCBcdWJjMThcdWI0ZGNcdWMyZGMgXHVjODc0XHVjN2FjXHVkNTVjXHViMmU0LjxcL3A+XHJcblxyXG48cD5cclxuXHRcdWM2MDhcdWI5N2NcdWI0ZTRcdWM1YjQsIFNcdWFjMDAgMTIzXHVjNzc0XHViYTc0LCA5NDdcdWM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