public class Anagram {
    public static void main(String[] args) {
	(new Anagram()).doAnagram(args[0], 0);
    }

    public void doAnagram (String word, int loc){
	if (loc == (word.length()-1)) {
		System.out.println(word);
		return;
	    }
	for(int i=loc; i<word.length(); i++) {
	    doAnagram(word, loc+1);
	    word = rotate(word, loc);
	}
    }
    private String rotate(String w, int l) {
	if (l>0)
	    return w.substring(0,l)+w.substring(w.length()-1)+w.substring(l, w.length()-1);
	else
	    return w.substring(w.length()-1)+w.substring(l, w.length()-1);
    }
}
