Few test cases are failed,please check my approach

Print all the distinct permutations in a lexicographic order such that each permutation is in a new line. Note that there should not be any duplicate permutations.
try for this input
ABAA
correct output
AAAB
AABA
ABAA
BAAA
your output:
ABAA
AABA
AAAB
BAAA
AABA
AAAB
ABAA
AAAB
AABA