#K54527. Palindromic Sequence Steps

    ID: 29773 Type: Default 1000ms 256MiB

Palindromic Sequence Steps

Palindromic Sequence Steps

You are given a list of integers. For each integer, you are required to determine how many steps are needed to transform it into a palindrome by using the following process:

  • Check if the integer is a palindrome. If it is, the number of steps is 0.
  • If not, reverse its digits and add the reversed number to the original number.
  • Repeat the process with the new number.

If the number does not become a palindrome within \(1000\) iterations, output "FAIL" for that case.

Note: An integer is considered a palindrome if it reads the same forward and backward. For example, \(121\) is a palindrome while \(123\) is not.

inputFormat

The first line of input contains a single integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains one positive integer \(N\).

Example:

3
23
87
196

outputFormat

For each test case, output the number of steps required to reach a palindrome, or output "FAIL" if a palindrome is not reached within \(1000\) iterations. Each answer should be printed on a new line.

Example Output:

1
4
FAIL
## sample
1
23
1

</p>