CF2202B ABAB Construction
Description
There is a string $ T $ of length $ n $ , such that $ T_i= $ 'a' for all odd $ i $ and $ T_i= $ 'b' for all even $ i $ .
One day, Bob generated a string $ S $ with the following algorithm.
1. Initialize $ S $ to the empty string.
2. Remove either the first letter or the last letter from $ T $ , and append it to $ S $ .
3. If $ T $ is empty, terminate and return the string $ S $ . Otherwise, go back to the second step.
Then, Bob wrote down the generated string $ S $ on a note and forgot about it for a few years. The note was worn out when Bob found it, and someone might have secretly changed some letters. Of course, Bob wants to know if someone did alter the string!
You are given a string $ X $ of length $ n $ , which consists of 'a', 'b', and '?'.
Please determine if there exists a string $ A $ which satisfies the following conditions:
- $ |A|=n $ ;
- $ A_i $ is either 'a' or 'b' for all $ 1 \le i \le n $ ;
- $ A_i=X_i $ for all $ 1 \le i \le n $ such that $ X_i $ is not '?';
- The string $ A $ can be generated from the algorithm described above.
Input Format
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows.
The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 200\,000 $ ).
The second line of each test case contains a string $ X $ of length $ n $ , consisting of 'a', 'b', and '?'.
It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 200\,000 $ .
Output Format
If there is a string $ A $ that satisfies all conditions, output "YES" on a separate line.
If there is no string $ A $ that satisfies all conditions, output "NO" on a separate line.
You can output the answer in any case. For example, the strings "yEs", "yes", "Yes" will also be recognized as positive responses.
Explanation/Hint
For the second test case, the string "baaba" cannot be generated by the algorithm described above.
For the third test case, the string "abaab" can be generated by the algorithm described above:
1. Initially, $ T $ is "ababa" and $ S $ is empty.
2. Remove the first letter from $ T $ . $ T $ becomes "baba" and $ S $ becomes "a".
3. Remove the first letter from $ T $ . $ T $ becomes "aba" and $ S $ becomes "ab".
4. Remove the last letter from $ T $ . $ T $ becomes "ab" and $ S $ becomes "aba".
5. Remove the first letter from $ T $ . $ T $ becomes "b" and $ S $ becomes "abaa".
6. Remove the last letter from $ T $ . $ T $ becomes empty and $ S $ becomes "abaab".