f=lambda s,n=1:s==2*s[:n]or''<s[n:]>-f(s,n+1)<f(s[n:])*f(s[:n])
for s in 'aa abaaba bbababbb aabaaababbbaba babababa bbbbbbbbbbbb a ba baab abaabaaba bbbbbbbbbbbbbbb baababbabaaaab aaaaabbaaaaa'.split():
print(repr(f(s)))
Zj1sYW1iZGEgcyxuPTE6cz09MipzWzpuXW9yJyc8c1tuOl0+LWYocyxuKzEpPGYoc1tuOl0pKmYoc1s6bl0pCiAKZm9yIHMgaW4gJ2FhIGFiYWFiYSBiYmFiYWJiYiBhYWJhYWFiYWJiYmFiYSBiYWJhYmFiYSBiYmJiYmJiYmJiYmIgYSBiYSBiYWFiIGFiYWFiYWFiYSBiYmJiYmJiYmJiYmJiYmIgYmFhYmFiYmFiYWFhYWIgYWFhYWFiYmFhYWFhJy5zcGxpdCgpOgoJcHJpbnQocmVwcihmKHMpKSk=