After getting bored by playing with crayons, you decided to switch to Legos! Today, you're working with a long strip, with height
and length , some positions of which are occupied by by Lego pieces.
In one second, you can either remove two adjacent Lego pieces from the strip (if both are present), or add two Lego pieces to adjacent positions (if both are absent). You can only add or remove Lego's at two adjacent positions at the same time, as otherwise your chubby fingers run into precision issues.
You want to know exactly how much time you'll spend playing with Legos. You value efficiency, so given some starting state and some ending state, you'll always spend the least number of seconds to transform the starting state into the ending state. If it's impossible to transform the starting state into the ending state, you just skip it (so you spend seconds).
The issue is that, for some positions, you don't remember whether there were Legos there or not (in either the starting state, the ending state, or both). Over all pairs of (starting state, ending state) that are consistent with your memory, find the total amount of time it will take to transform the starting state to the ending state. Print this value modulo ().
The first line contains one integer () — the number of test cases. Then cases follow.
The first line of each test case contains one integer () — the size of the Lego strip.
The second line of each test case contains a string of length , consisting of the characters 0, 1, and ? — your memory of the starting state:
- 1 represents a position that definitely has a Lego piece,
- 0 represents a position that definitely does not have a Lego piece,
- and ? represents a position that you don't remember.
The third line of each test case contains a string of length , consisting of the characters 0, 1, and ? — your memory of the ending state. It follows a similar format to the starting state.
It's guaranteed that the sum of over all test cases doesn't exceed .
For each test case, output a single integer — the answer to the problem modulo ().
6 2 00 11 3 ??? ??? 3 ??1 0?0 4 ??0? ??11 5 ????? 0??1? 10 ?01??01?1? ??100?1???
1 16 1 14 101 1674
ConversionConversion EmoticonEmoticon