$_=<>;++$%while s/BA/AB/;print$%