This problem is different from the easy version. In this version Ujan makes at most $2n$ swaps. In addition, $k \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 $s$ and $t$ of length $n$ 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 $2n$ times: he takes two positions $i$ and $j$ ($1 \le i,j \le n$, the values $i$ and $j$ can be equal or different), and swaps the characters $s_i$ and $t_j$.
Ujan's goal is to make the strings $s$ and $t$ equal. He does not need to minimize the number of performed operations: any sequence of operations of length $2n$ or shorter is suitable.
-----Input-----
The first line contains a single integer $k$ ($1 \leq k \leq 1000$), the number of test cases.
For each of the test cases, the first line contains a single integer $n$ ($2 \leq n \leq 50$), the length of the strings $s$ and $t$. 
Each of the next two lines contains the strings $s$ and $t$, each having length exactly $n$. 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 $2n$ operations and "No" otherwise. You can print each letter in any case (upper or lower).
In the case of "Yes" print $m$ ($1 \le m \le 2n$) on the next line, where $m$ is the number of swap operations to make the strings equal. Then print $m$ lines, each line should contain two integers $i, j$ ($1 \le i, j \le n$) meaning that Ujan swaps $s_i$ and $t_j$ during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than $2n$ is suitable.
-----Example-----
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
1
1 4
No
No
Yes
3
1 2
3 1
2 3
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
for _ in range(int(input())):
    n = int(input())
    s = [i for i in input()]
    t = [i for i in input()]
    d = defaultdict(int)
    for i in range(n):
        d[s[i]]+=1
        d[t[i]]+=1
    if len(list(d.keys()))>n or sum(i%2 for i in list(d.values())):
        print('No')
    else:
        ans = []
        for i in range(n):
            if s[i]!=t[i]:
                for j in range(i+1,n):
                    if s[j]!=t[j]:
                        if s[i]==s[j]:
                            ans.append([j,i])
                            s[j],t[i] = t[i],s[j]
                            break
                        elif s[i]==t[j]:
                            ans.append([j,j])
                            s[j],t[j] = t[j],s[j]
                            ans.append([j,i])
                            s[j],t[i] = t[i],s[j]
                            break
                        elif t[i]==t[j]:
                            ans.append([i,j])
                            s[i],t[j] = t[j],s[i]
                            break
                        elif t[i]==s[j]:
                            ans.append([j,j])
                            s[j],t[j] = t[j],s[j]
                            ans.append([i,j])
                            s[i],t[j] = t[j],s[i]
                            break
            #assert(s[i]==t[i])
        #assert(len(ans)<=2*n)
        print('Yes')
        print(len(ans))
        for i in ans:
            print(i[0]+1,i[1]+1)




        



from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
for _ in range(int(input())):
    n = int(input())
    s = [i for i in input()]
    t = [i for i in input()]
    d = defaultdict(int)
    for i in range(n):
        d[s[i]]+=1
        d[t[i]]+=1
    if len(list(d.keys()))>n or sum(i%2 for i in list(d.values())):
        print('No')
    else:
        ans = []
        for i in range(n):
            if s[i]!=t[i]:
                for j in range(i+1,n):
                    if s[j]!=t[j]:
                        if s[i]==s[j]:
                            ans.append([j,i])
                            s[j],t[i] = t[i],s[j]
                            break
                        elif s[i]==t[j]:
                            ans.append([j,j])
                            s[j],t[j] = t[j],s[j]
                            ans.append([j,i])
                            s[j],t[i] = t[i],s[j]
                            break
                        elif t[i]==t[j]:
                            ans.append([i,j])
                            s[i],t[j] = t[j],s[i]
                            break
                        elif t[i]==s[j]:
                            ans.append([j,j])
                            s[j],t[j] = t[j],s[j]
                            ans.append([i,j])
                            s[i],t[j] = t[j],s[i]
                            break
            #assert(s[i]==t[i])
        #assert(len(ans)<=2*n)
        print('Yes')
        print(len(ans))
        for i in ans:
            print(i[0]+1,i[1]+1)




        


