#P1243B2. Character Swap (Hard Version)
Character Swap (Hard Version)
No submission language available for this problem.
Description
This problem is different from the easy version. In this version Ujan makes at most swaps. In addition, and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings and of length consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation at most times: he takes two positions and (, the values and can be equal or different), and swaps the characters and .
Ujan's goal is to make the strings and equal. He does not need to minimize the number of performed operations: any sequence of operations of length or shorter is suitable.
The first line contains a single integer (), the number of test cases.
For each of the test cases, the first line contains a single integer (), the length of the strings and .
Each of the next two lines contains the strings and , each having length exactly . The strings consist only of lowercase English letters. It is guaranteed that strings are different.
For each test case, output "Yes" if Ujan can make the two strings equal with at most operations and "No" otherwise. You can print each letter in any case (upper or lower).
In the case of "Yes" print () on the next line, where is the number of swap operations to make the strings equal. Then print lines, each line should contain two integers () meaning that Ujan swaps and during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than is suitable.
Input
The first line contains a single integer (), the number of test cases.
For each of the test cases, the first line contains a single integer (), the length of the strings and .
Each of the next two lines contains the strings and , each having length exactly . The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal with at most operations and "No" otherwise. You can print each letter in any case (upper or lower).
In the case of "Yes" print () on the next line, where is the number of swap operations to make the strings equal. Then print lines, each line should contain two integers () meaning that Ujan swaps and during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than is suitable.