------
## 最终结论
```python
import sys

input = sys.stdin.read
data = input().strip().split()

k = int(data[0])
index = 1
results = []

for _ in range(k):
    n = int(data[index])
    s = list(data[index + 1])
    t = list(data[index + 2])
    index += 3
    
    if sorted(s) != sorted(t):
        results.append("No")
        continue
    
    swaps = []
    
    for i in range(n):
        if s[i] != t[i]:
            found = False
            
            # Find a matching character in the rest of s
            for j in range(i + 1, n):
                if s[j] == s[i]:
                    swaps.append((j + 1, i + 1))
                    s[j], t[i] = t[i], s[j]
                    found = True
                    break
            
            # If not found, find a matching character in the rest of t
            if not found:
                for j in range(i + 1, n):
                    if t[j] == s[i]:
                        swaps.append((i + 2, j + 1))
                        swaps.append((i + 2, i + 1))
                        s[i + 1], t[j] = t[j], s[i + 1]
                        s[i + 1], t[i] = t[i], s[i + 1]
                        break
    
    results.append("Yes")
    results.append(str(len(swaps)))
    for swap in swaps:
        results.append(f"{swap[0]} {swap[1]}")

print("\n".join(results))
```