You are to write a program that generates all possible words from a given set of letters.
Example: Given the word “abc”, your program should – by exploring all different combinations of the three letters – output the words “abc”, “acb”, “bac”, “bca”, “cab”, and “cba”.
In the word taken from the input, some letters may appear more than once. For a given word, your program should not produce the same word more than once, and the words should be output in alphabetically ascending order.
The input consists of several words. The first line contains the number of words to follow. Each of the following lines contains one word. A word consists of uppercase or lowercase letters from A to Z. Uppercase and lowercase letters are to be considered different.
For each word in the input, the output should contain all different words that can be generated with the letters of the given word. The words generated from the same input word should be output one per line, in alphabetically ascending order. An uppercase letter goes before the corresponding lowercase letter.
Output for Sample Input
|University of Debrecen; Faculty of Informatics; v. 03/01/2019|