Anagram generation#1533

Anagram generation

1 second
128 megabytes
Easy

Write a program that generates all possible unique words from a given set of letters.

For example, from the word , all possible permutations of the letters are: , , , , , and .

Input words may contain duplicate letters. The program must not output the same word more than once. All words should be printed in ascending alphabetical order.

Input

The first line contains the number of test cases . Each of the following lines contains one word consisting of Latin letters (from to ). Uppercase and lowercase letters are considered different.

Output

For each test case, print all unique words that can be formed from the given letters in ascending alphabetical order. Each word should be printed on a separate line. In alphabetical order, uppercase letters are considered smaller than their lowercase counterparts.

Examples

Example 1

Loading
Loading