from 第四回 アルゴリズム実技検定 PAST4E E - アナグラム
def solve(N, S):
from itertools import permutations
rS = "".join(reversed(S))
for p in permutations(S):
ret = "".join(p)
if ret != S and ret != rS:
return ret
return "None"