sub f{"@_"=~/\pL/?-55+ord$&:pop} <>; for(<>){ ($b)=sort{1}sort/./g; $b=1+f$b; $x=0; for(/./g){ ($x*=f$b)+=f$_ } !$%|$x<$%and$%=$x } print$%