Home => ProblemSet => 2.12-80:[POJ1854]Evil Straw Warts Live
Problem2042--2.12-80:[POJ1854]Evil Straw Warts Live

2042: 2.12-80:[POJ1854]Evil Straw Warts Live

Time Limit: 2 Sec  Memory Limit: 64 MB  Submit: 0  Solved: 1
[ Submit ] [ Status ] [ Creator: ][ 参考程序 ]

Description

A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, compute the number of swaps necessary to transform the string into a palindrome. By swap we mean reversing the order of two adjacent symbols. For example, the string "mamad" may be transformed into the palindrome "madam" with 3 swaps:
swap "ad" to yield "mamda"
swap "md" to yield "madma"
swap "ma" to yield "madam"

Input

The first line of input gives n, n <= 1000, the number of test cases. 
For each test case, one line of input follows, containing a string of up to 8000 lowercase letters.

Output

Output consists of one line per test case. 
This line will contain the number of swaps, or "Impossible" if it is not possible to transform the input to a palindrome.

Sample Input Copy

3
mamad
asflkj
aabb

Sample Output Copy

3
Impossible
2

Source/Category