#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 2n2n swaps. In addition, k1000,n50k \le 1000, n \le 50 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 ss and tt of length nn 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 2n2n times: he takes two positions ii and jj (1i,jn1 \le i,j \le n, the values ii and jj can be equal or different), and swaps the characters sis_i and tjt_j.

Ujan's goal is to make the strings ss and tt equal. He does not need to minimize the number of performed operations: any sequence of operations of length 2n2n or shorter is suitable.

The first line contains a single integer kk (1k10001 \leq k \leq 1000), the number of test cases.

For each of the test cases, the first line contains a single integer nn (2n502 \leq n \leq 50), the length of the strings ss and tt.

Each of the next two lines contains the strings ss and tt, each having length exactly nn. 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 2n2n operations and "No" otherwise. You can print each letter in any case (upper or lower).

In the case of "Yes" print mm (1m2n1 \le m \le 2n) on the next line, where mm is the number of swap operations to make the strings equal. Then print mm lines, each line should contain two integers i,ji, j (1i,jn1 \le i, j \le n) meaning that Ujan swaps sis_i and tjt_j during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than 2n2n is suitable.

Input

The first line contains a single integer kk (1k10001 \leq k \leq 1000), the number of test cases.

For each of the test cases, the first line contains a single integer nn (2n502 \leq n \leq 50), the length of the strings ss and tt.

Each of the next two lines contains the strings ss and tt, each having length exactly nn. 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 2n2n operations and "No" otherwise. You can print each letter in any case (upper or lower).

In the case of "Yes" print mm (1m2n1 \le m \le 2n) on the next line, where mm is the number of swap operations to make the strings equal. Then print mm lines, each line should contain two integers i,ji, j (1i,jn1 \le i, j \le n) meaning that Ujan swaps sis_i and tjt_j during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than 2n2n is suitable.

Samples

Sample Input 1

4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca

Sample Output 1

Yes
1
1 4
No
No
Yes
3
1 2
3 1
2 3