#C6282. Palindrome Formation with One Removal

    ID: 50025 Type: Default 1000ms 256MiB

Palindrome Formation with One Removal

Palindrome Formation with One Removal

Given a string s, determine whether it is possible to form a palindrome by removing at most one character. A palindrome is a string that reads the same backward as forward. For example, if s = "abca", you can remove the character 'b' or 'c' to get "aca" or "aba", both of which are palindromes. If s is already a palindrome, it is also considered valid.

Your task is to output YES if the string can be transformed into a palindrome by removing at most one character, and NO otherwise.

The condition for checking can be formalized in \(O(n)\) time where \(n\) is the length of the string. Specifically, you need to check if there exist indices \(i, j\) such that by ignoring either the character at \(i\) or at \(j\), the remaining string becomes a palindrome.

inputFormat

The first line of input contains an integer T indicating the number of test cases. Each of the following T lines contains a non-empty string s composed of lowercase or uppercase letters.

outputFormat

For each test case, output a single line with YES if the string can be transformed into a palindrome by removing at most one character, and NO otherwise.

## sample
3
abca
abc
a
YES

NO YES

</p>