SPOJ DNALAB

Problem LInk :https://www.spoj.com/problems/DNALAB/
My approach :
I have thought of dp bitmask solution to solve this problem
but i am not able to figure the solution for the case when both the strings are of same length and we need to pick the lexicographically smallest one.
Can anyone help with this case ??