#P1937B. Binary Path
Binary Path
Description
You are given a grid filled with zeros and ones. Let the number at the intersection of the -th row and the -th column be .
There is a grasshopper at the top-left cell that can only jump one cell right or downwards. It wants to reach the bottom-right cell . Consider the binary string of length consisting of numbers written in cells of the path without changing their order.
Your goal is to:
- Find the lexicographically smallest string you can attain by choosing any available path;
- Find the number of paths that yield this lexicographically smallest string.
If two strings and have the same length, then is lexicographically smaller than if and only if in the first position where and differ, the string has a smaller element than the corresponding element in .
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains a binary string ( is either or ).
The third line of each test case contains a binary string ( is either or ).
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output two lines:
- The lexicographically smallest string you can attain by choosing any available path;
- The number of paths that yield this string.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains a binary string ( is either or ).
The third line of each test case contains a binary string ( is either or ).
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output two lines:
- The lexicographically smallest string you can attain by choosing any available path;
- The number of paths that yield this string.
Note
In the first test case, the lexicographically smallest string is . There are two paths that yield this string:

In the second test case, the lexicographically smallest string is . There is only one path that yields this string:
