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

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: String algorithms


Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	flag1 = 1
	steps = []
	for i in range(n):
		flag = 0
		if a[i] == b[i]:
			continue
		for j in range(i + 1, n):
			if a[j] != b[j] and a[j] == a[i]:
				steps.append((j + 1, i + 1))
				(a[j], b[i]) = (b[i], a[j])
				flag = 1
				break
		if flag == 0:
			for j in range(i + 1, n):
				if b[j] != a[j] and b[j] == a[i]:
					steps.append((j + 1, j + 1))
					(a[j], b[j]) = (b[j], a[j])
					steps.append((j + 1, i + 1))
					(a[j], b[i]) = (b[i], a[j])
					flag = 1
					break
		if flag == 0:
			flag1 = 0
			break
	if flag1 == 0:
		print('No')
	else:
		print('yes')
		print(len(steps))
		for i in steps:
			print(*i)


import sys
import collections
import heapq
import math
input = sys.stdin.readline

def rints():
	return map(int, input().strip().split())

def rstr():
	return input().strip()

def rint():
	return int(input().strip())

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
k = rint()
for _ in range(k):
	n = rint()
	S = [i for i in rstr()]
	T = [i for i in rstr()]
	ans = []
	for i in range(n):
		if S[i] != T[i]:
			cont = False
			for j in range(i + 1, n):
				if S[j] != T[j] and S[i] == S[j]:
					(T[i], S[j]) = (S[j], T[i])
					ans.append([j, i])
					cont = True
					break
			if cont:
				continue
			for j in range(i + 1, n):
				if S[j] != T[j] and S[i] == T[j]:
					(T[j], S[j]) = (S[j], T[j])
					ans.append([j, j])
					(T[i], S[j]) = (S[j], T[i])
					ans.append([j, i])
					cont = True
					break
	if S == T:
		print('Yes')
		print(len(ans))
		for (i, j) in ans:
			print(i + 1, ' ', j + 1)
	else:
		print('No')


for _ in range(int(input())):
	N = int(input())
	s = [i for i in input()]
	t = [i for i in input()]
	charCount = [0] * 26
	for i in s:
		charCount[ord(i) - ord('a')] += 1
	for i in t:
		charCount[ord(i) - ord('a')] += 1
	flag = True
	for i in charCount:
		if i & 1:
			flag = False
			break
	ans = []
	if flag:
		print('Yes')
		for i in range(N - 1):
			if s[i] == t[i]:
				continue
			else:
				go = True
				for ss in range(i + 1, N):
					if s[ss] == s[i]:
						ans.append((ss + 1, i + 1))
						(t[i], s[ss]) = (s[ss], t[i])
						go = False
						break
				if go:
					for tt in range(i + 1, N):
						if t[tt] == s[i]:
							ans.append((tt + 1, tt + 1))
							(t[tt], s[tt]) = (s[tt], s[tt])
							ans.append((tt + 1, i + 1))
							(s[tt], t[i]) = (t[i], s[tt])
							break
		print(len(ans))
		for x in ans:
			print(*x)
	else:
		print('No')


k = int(input())
while k:
	n = int(input())
	s = list(input())
	t = list(input())
	c = 0
	l = [0] * 27
	d = {}
	for i in range(n):
		l[ord(s[i]) - 97] += 1
		l[ord(t[i]) - 97] += 1
	for i in l:
		if i % 2 != 0:
			c = 1
			break
	count = 0
	if c == 1:
		print('No')
	else:
		ans = []
		for i in range(n):
			if s[i] != t[i]:
				for j in range(i + 1, n):
					if t[j] == t[i]:
						t[j] = s[i]
						s[i] = t[i]
						d[i + 1] = 9
						ans.append(i + 1)
						ans.append(j + 1)
						break
				if d.get(i + 1, 0) == 0:
					for j in range(i + 1, n):
						if s[j] == t[i]:
							s[j] = t[i + 1]
							t[i + 1] = t[i]
							ans.append(j + 1)
							ans.append(i + 2)
							t[i + 1] = s[i]
							s[i] = t[i]
							ans.append(i + 1)
							ans.append(i + 2)
							break
		ll = len(ans) // 2
		if ll == 0:
			print('No')
		else:
			print('Yes')
			print(ll)
			m = 0
			for i in range(ll):
				print(ans[m], ans[m + 1], end=' ')
				m += 2
				print()
	k -= 1


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
q = int(input())
for _ in range(q):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	if s1 == s2:
		print('YES')
		print(1)
		print(1, 1)
		continue
	d = {}
	d1 = {}
	d2 = {}
	for j in s1:
		d[j] = d.get(j, 0) + 1
		d1[j] = d1.get(j, 0) + 1
		if j not in s2:
			d2[j] = 0
	for j in s2:
		d[j] = d.get(j, 0) + 1
		d2[j] = d2.get(j, 0) + 1
		if j not in s1:
			d1[j] = 0
	f = True
	for j in d:
		if d[j] % 2 != 0:
			print('No')
			f = False
			break
	if not f:
		continue
	print('YES')
	ans = []
	for i in range(n):
		if s1[i] != s2[i]:
			k = s1[i]
			if d2[k] != 0:
				for j in range(i + 1, n):
					if s2[j] == s1[i]:
						ans.append((n, j + 1))
						ans.append((n, i + 1))
						d1[k] -= 1
						d2[s2[j]] -= 1
						d2[s2[i]] -= 1
						d2[s1[n - 1]] += 1
						d1[s2[i]] += 1
						(s1[n - 1], s2[j]) = (s2[j], s1[n - 1])
						(s1[n - 1], s2[i]) = (s2[i], s1[n - 1])
						break
			else:
				for j in range(i + 1, n):
					if s1[j] == s1[i]:
						ans.append((j + 1, i + 1))
						d1[k] -= 1
						d1[s2[i]] += 1
						d2[s2[i]] -= 1
						(s1[j], s2[i]) = (s2[i], s1[j])
						break
		else:
			d1[s1[i]] -= 1
			d2[s1[i]] -= 1
	print(len(ans))
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	s1 = str(input())
	t1 = str(input())
	(c, i) = (0, 0)
	s = list(s1)
	t = list(t1)
	l = []
	while i < n:
		if s[i] != t[i]:
			left = i + 1
			while left < n and s[left] != s[i]:
				left += 1
			if left < n:
				(t[i], s[left]) = (s[left], t[i])
				l.append((left, i))
				i += 1
			else:
				left = i + 1
				while left < n and t[left] != s[i]:
					left += 1
				if left < n:
					(s[left], t[left]) = (t[left], s[left])
					l.append((left, left))
				else:
					c = 1
					break
		else:
			i += 1
	if c == 1:
		print('No')
	else:
		print('Yes')
		t = len(l)
		if t <= 2 * n:
			print(t)
			for i in range(len(l)):
				print(l[i][0] + 1, l[i][1] + 1)
		else:
			print('No')


def solve(n, s, t):
	x = s + t
	for v in set(s) | set(t):
		if x.count(v) % 2 != 0:
			return ['No']
	r = ['Yes']
	sList = list(s)
	tList = list(t)
	i = 0
	while i < n:
		if sList[i] != tList[i]:
			if sList[i] in ''.join(sList[i + 1:]):
				j = i + 1 + ''.join(sList[i + 1:]).find(sList[i])
				(sList[j], tList[i]) = (tList[i], sList[j])
				r.append(' '.join(map(str, [j + 1, i + 1])))
			else:
				j = i + 1 + ''.join(tList[i + 1:]).find(sList[i])
				(sList[j], tList[j]) = (tList[j], sList[j])
				r.append(' '.join(map(str, [j + 1, j + 1])))
				(sList[j], tList[i]) = (tList[i], sList[j])
				r.append(' '.join(map(str, [j + 1, i + 1])))
		i += 1
	r.insert(1, len(r) - 1)
	return r
r = []
for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	r.extend(solve(n, s, t))
print(*r, sep='\n')


def f():
	n = int(input())
	s = list(input())
	t = list(input())
	ans = []
	for i in range(n - 1):
		if s[i] != t[i]:
			j = i + 1
			while j < n and s[j] != s[i]:
				j += 1
			if j != n:
				(t[i], s[j]) = (s[j], t[i])
				ans += [[j + 1, i + 1]]
			else:
				j = i + 1
				while j < n and t[j] != s[i]:
					j += 1
				if j != n:
					(t[j], s[i + 1]) = (s[i + 1], t[j])
					ans += [[i + 2, j + 1]]
					(s[i + 1], t[i]) = (t[i], s[i + 1])
					ans += [[i + 2, i + 1]]
				else:
					print('No')
					return
	if s == t:
		print('Yes')
		print(len(ans))
		for e in ans:
			print(*e)
	else:
		print('No')
q = int(input())
for qq in range(q):
	f()


import sys, math, bisect

def input():
	return sys.stdin.readline()[:-1]

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		s = input()
		t = input()
		A = [0 for k in range(30)]
		for e in s:
			A[ord(e) - 97] += 1
		for e in t:
			A[ord(e) - 97] += 1
		f = 0
		for e in A:
			if e % 2 == 1:
				f = 1
				break
		if f == 1:
			print('No')
		else:
			print('Yes')
			S = [str(e) for e in s]
			T = [str(e) for e in t]
			ans = []
			for k in range(n - 1):
				if S[k] != T[k]:
					for l in range(k + 1, n):
						if S[k] == S[l]:
							(T[k], S[l]) = (S[l], T[k])
							ans.append([l + 1, k + 1])
							break
						if S[k] == T[l]:
							(S[l], T[l]) = (T[l], S[l])
							ans.append([l + 1, l + 1])
							(S[l], T[k]) = (T[k], S[l])
							ans.append([l + 1, k + 1])
							break
			print(len(ans))
			for e in ans:
				print(*e)
main()


T = int(input())
for t in range(T):
	N = int(input())
	s = list(input())
	t = list(input())
	i = 0
	possible = True
	res = []
	while i < N:
		if s[i] != t[i]:
			j = i + 1
			found = False
			while j < N:
				if s[i] == s[j]:
					res.append((j, i))
					(s[j], t[i]) = (t[i], s[j])
					found = True
					break
				elif s[i] == t[j]:
					res.append((j, j))
					(s[j], t[j]) = (t[j], s[j])
					res.append((j, i))
					(s[j], t[i]) = (t[i], s[j])
					found = True
					break
				j += 1
			if not found:
				possible = False
				break
		i += 1
	if possible:
		print('Yes')
		print(len(res))
		for (i, j) in res:
			print(i + 1, j + 1)
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	s1 = str(input())
	s2 = str(input())
	ls1 = list(s1)
	ls2 = list(s2)
	l1 = []
	l2 = []
	ans = 0
	f = 0
	for i in range(97, 123):
		temp = chr(i)
		c = 0
		for j in range(n):
			if s1[j] == temp:
				c += 1
			if s2[j] == temp:
				c += 1
		if c % 2 != 0:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		for i in range(n):
			if ls1[i] != ls2[i]:
				v = 0
				for j in range(i + 1, n):
					if ls1[i] == ls1[j]:
						l1.append(j + 1)
						l2.append(i + 1)
						ans += 1
						t = ls1[j]
						ls1[j] = ls2[i]
						ls2[i] = t
						v = 1
						break
				if v == 0:
					for j in range(i + 1, n):
						if ls2[j] == ls1[i]:
							ans += 2
							l1.append(j + 1)
							l2.append(j + 1)
							l1.append(j + 1)
							l2.append(i + 1)
							t = ls1[j]
							ls1[j] = ls2[j]
							ls2[j] = t
							t = ls1[j]
							ls1[j] = ls2[i]
							ls2[i] = t
							break
		print('YES')
		print(ans)
		for i in range(ans):
			print(l1[i], l2[i])


def solve(s, t, n, ans):
	s = list(s)
	t = list(t)
	moves = ['Yes']
	for i in range(n):
		if s[i] != t[i]:
			req = t[i]
			found = False
			for j in range(i + 1, n):
				if t[j] == req:
					index = j
					found = True
					break
			if not found:
				for j in range(i + 1, n):
					if s[j] == req:
						index = j
						found = True
						break
			else:
				moves.append(str(i + 1) + ' ' + str(index + 1))
				(s[i], t[index]) = (t[index], s[i])
				continue
			if not found:
				ans.append(['No'])
				return
			else:
				moves.append(str(index + 1) + ' ' + str(index + 1))
				(s[index], t[index]) = (t[index], s[index])
				moves.append(str(i + 1) + ' ' + str(index + 1))
				(s[i], t[index]) = (t[index], s[i])
	moves.insert(1, len(moves) - 1)
	ans.append(moves)

def main():
	ans = []
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		t = input()
		solve(s, t, n, ans)
	for i in ans:
		for j in i:
			print(j)
main()


t = int(input())
for p in range(t):
	n = int(input())
	a = input()
	b = input()
	dic = {}
	for i in range(n):
		if a[i] in dic:
			dic[a[i]] += 1
		else:
			dic[a[i]] = 1
		if b[i] in dic:
			dic[b[i]] += 1
		else:
			dic[b[i]] = 1
	flag = 0
	for d in dic:
		if dic[d] % 2 != 0:
			flag = 1
	if flag == 1:
		print('No')
	else:
		print('Yes')
		ans = []
		for i in range(n):
			if a[i] != b[i]:
				x = a.find(a[i], i + 1)
				if x != -1:
					ans.append([x + 1, i + 1])
					a = a[:x] + b[i] + a[x + 1:]
					b = b[:i] + a[i] + b[i + 1:]
				else:
					s = b.find(a[i], i + 1)
					ans.append([s + 1, s + 1])
					ans.append([s + 1, i + 1])
					rd = a[s]
					a = a[:s] + b[i] + a[s + 1:]
					b = b[:i] + b[s] + b[i + 1:s] + rd + b[s + 1:]
		print(len(ans))
		for d in ans:
			print(*d)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def swap(s, t, i, j):
	p.append((i + 1, j + 1))
	(s[i], t[j]) = (t[j], s[i])

def find(s, v, i):
	for j in range(i, len(s)):
		if s[j] == v:
			return j
	return -1

def solve():
	global p
	n = mint()
	s = list(minp())
	t = list(minp())
	c = [0] * 26
	for i in s:
		c[ord(i) - ord('a')] += 1
	for i in t:
		c[ord(i) - ord('a')] += 1
	same = True
	for i in range(26):
		if c[i] % 2 != 0:
			print('No')
			return
	p = []
	for z in range(100):
		for i in range(n):
			if s[i] != t[i]:
				if find(s, s[i], i + 1) != -1:
					swap(s, t, find(s, s[i], i + 1), i)
				elif find(t, t[i], i + 1) != -1:
					swap(s, t, i, find(t, t[i], i + 1))
				else:
					swap(s, t, i, i)
					if find(s, s[i], i + 1) != -1:
						swap(s, t, find(s, s[i], i + 1), i)
					elif find(t, t[i], i + 1) != -1:
						swap(s, t, i, find(t, t[i], i + 1))
	if len(p) <= 2 * n:
		print('Yes')
		print(len(p))
		for i in p:
			print(*i)
		return
	print('No')
for i in range(mint()):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	ml = []
	for i in range(n - 1):
		if a[i] != b[i]:
			if a[i] in a[i + 1:]:
				ind = i + 1 + a[i + 1:].index(a[i])
				(b[i], a[ind]) = (a[ind], b[i])
				ml.append((ind + 1, i + 1))
			elif a[i] in b[i + 1:]:
				ind1 = i + 1 + b[i + 1:].index(a[i])
				(a[i + 1], b[ind1]) = (b[ind1], a[i + 1])
				(b[i], a[i + 1]) = (a[i + 1], b[i])
				ml.append((i + 2, ind1 + 1))
				ml.append((i + 2, i + 1))
			else:
				break
	if a == b:
		print('Yes')
		print(len(ml))
		for i in ml:
			print(*i)
	else:
		print('No')


import sys, math, queue, collections
MOD = 10 ** 9 + 7

def equalize(i):
	if s[i] == t[i]:
		return True
	for j in range(i + 1, n):
		if s[j] == s[i]:
			ans.append((j + 1, i + 1))
			tc = s[j]
			s[j] = t[i]
			t[i] = tc
			return True
	for j in range(i + 1, n):
		if t[j] == s[i]:
			ans.append((n, j + 1))
			tc = s[-1]
			s[-1] = t[j]
			t[j] = tc
			ans.append((n, i + 1))
			tc = s[-1]
			s[-1] = t[i]
			t[i] = tc
			return True
	return False
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	stat = True
	ans = []
	for i in range(n):
		stat = stat and equalize(i)
	if stat:
		print('Yes')
		print(len(ans))
		for ai in ans:
			print(*ai)
	else:
		print('No')


n = int(input())
for i in range(n):
	l = int(input())
	str1 = input()
	str2 = input()
	list01 = list(str1)
	list02 = list(str2)
	list0 = list01[:]
	list0.extend(list02)
	nlist = []
	alist = []
	for j in list0:
		if j not in alist:
			a = list0.count(j)
			nlist.append(a)
			alist.append(j)
			if a % 2 != 0:
				print('No')
				break
	if a % 2 == 0:
		print('Yes')
		op = 0
		list1 = []
		list2 = []
		for c in range(l - 1):
			if str1[c] != str2[c]:
				d = str2.find(str2[c], c + 1)
				if d != -1:
					(list02[d], list01[c]) = (list01[c], list02[d])
					str1 = ''.join(list01)
					str2 = ''.join(list02)
					op += 1
					list1.append(c + 1)
					list2.append(d + 1)
				else:
					d = str1.find(str2[c], c + 1)
					(list02[l - 1], list01[d]) = (list01[d], list02[l - 1])
					(list02[l - 1], list01[c]) = (list01[c], list02[l - 1])
					str1 = ''.join(list01)
					str2 = ''.join(list02)
					op += 2
					list1.extend([d + 1, c + 1])
					list2.extend([l, l])
		print(op)
		for k in range(op):
			print(list1[k], list2[k], sep=' ')


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def check1(C):
	for v in C.values():
		if v % 2 != 0:
			return False
	return True

def check2(S, T):
	ans = []
	for i in range(N):
		if S[i] != T[i]:
			try:
				j = S[i + 1:].index(S[i]) + i + 1
				(S[j], T[i]) = (T[i], S[j])
				ans.append((j, i))
			except:
				j = T[i + 1:].index(S[i]) + i + 1
				(S[i], T[j]) = (T[j], S[j])
				ans.append((j, j))
				(S[j], T[i]) = (T[i], S[j])
				ans.append((j, i))
	return ans
for _ in range(INT()):
	N = INT()
	S = list(input())
	T = list(input())
	C1 = Counter(S)
	C2 = Counter(T)
	C = Counter(S + T)
	if not check1(C):
		No()
		continue
	ans = check2(S, T)
	Yes()
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)


for i in range(int(input())):
	(a, s, t) = (int(input()), input(), input())
	if len([False for n in [(s + t).count(i) for i in set(s + t)] if n % 2]):
		print('No')
	else:
		print('Yes')
		s = [' '] + [i for i in s]
		t = [' '] + [i for i in t]
		c = []
		while len(s):
			(r, d) = (s.pop(), t.pop())
			if r != d:
				try:
					n = t.index(d)
					c.append(str(len(s)) + ' ' + str(n))
					t[n] = r
				except:
					c.append(str(len(s)) + ' ' + str(len(s)))
					n = s.index(d)
					c.append(str(n) + ' ' + str(len(s)))
					s[n] = r
		print(len(c))
		for i in c:
			print(i)


import sys
input = sys.stdin.readline
for q in range(int(input())):
	N = int(input())
	s = list(input().rstrip())
	t = list(input().rstrip())
	ans = []
	for i in range(N - 1):
		if s[i] != t[i]:
			for j in range(i + 1, N):
				if s[j] == s[i]:
					ans.append((j + 1, i + 1))
					(s[j], t[i]) = (t[i], s[j])
					break
				if t[j] == s[i]:
					ans.append((i + 2, j + 1))
					(s[i + 1], t[j]) = (t[j], s[i + 1])
					ans.append((i + 2, i + 1))
					(s[i + 1], t[i]) = (t[i], s[i + 1])
					break
	flag = True
	for i in range(N):
		if s[i] != t[i]:
			flag = False
	if flag and ans:
		print('Yes')
		print(len(ans))
		for (u, v) in ans:
			print(u, v)
	else:
		print('No')


from sys import stdin, stdout
for i in stdin:
	q = int(i)
	break

def swap(i, j):
	global s
	global m
	global t
	global M
	M.append([i + 1, j + 1])
	m += 1
	(s[i], t[j]) = (t[j], s[i])

def solve():
	global s
	global t
	global m
	global A
	for i in range(1, len(A)):
		if s[A[0]] == s[A[i]]:
			swap(A[i], A[0])
			if s[A[i]] == t[A[i]]:
				A = A[1:i] + A[i + 1:]
			else:
				del A[0]
			return 1
	for i in range(1, len(A)):
		if s[A[0]] == t[A[i]]:
			swap(A[i], A[i])
			swap(A[i], A[0])
			if s[A[i]] == t[A[i]]:
				A = A[1:i] + A[i + 1:]
			else:
				del A[0]
			return 1
	return 0
for i in range(q):
	for i in stdin:
		n = int(i)
		break
	for i in stdin:
		s = list(i.strip())
		break
	for i in stdin:
		t = list(i.strip())
		break
	A = []
	for i in range(n):
		if s[i] != t[i]:
			A.append(i)
	m = 0
	M = []
	while 1:
		if solve():
			if A == []:
				stdout.write('Yes\n')
				stdout.write(str(m) + '\n')
				for i in M:
					stdout.write(str(i[0]) + ' ' + str(i[1]) + '\n')
				break
		else:
			stdout.write('No\n')
			break


t = int(input())
from collections import defaultdict, Counter
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	l = [0] * 26
	for j in range(n):
		l[ord(s1[j]) - 97] += 1
		l[ord(s2[j]) - 97] += 1
	ans = True
	c1 = Counter(s1)
	c2 = Counter(s2)
	for j in l:
		if j % 2 != 0:
			ans = False
			break
	if ans == False:
		print('No')
	else:
		d1 = defaultdict(list)
		d2 = defaultdict(list)
		l1 = list(s1)
		l2 = list(s2)
		ans = 0
		l = []
		for j in range(n):
			d1[s1[j]].append(j)
			d2[s2[j]].append(j)
		for j in range(n - 1):
			if l1[j] != l2[j]:
				if c1[l1[j]] <= c2[l1[j]]:
					a = n
					ans += 2
					for k in d2[l1[j]]:
						if k > j:
							a = k
							break
					l2[a] = l1[j + 1]
					l1[j + 1] = l2[j]
					l2[j] = l1[j]
					d1 = defaultdict(list)
					d2 = defaultdict(list)
					for k in range(n):
						d1[l1[k]].append(k)
						d2[l2[k]].append(k)
					c1[l2[a]] -= 1
					c1[l1[j + 1]] += 1
					c2[l2[a]] += 1
					c2[l1[j + 1]] -= 1
					l.append([j + 2, a + 1])
					l.append([j + 2, j + 1])
				else:
					k = n
					for x in d1[l1[j]]:
						if x > j:
							k = x
							break
					(l2[j], l1[k]) = (l1[k], l2[j])
					ans += 1
					c1[l1[j]] -= 1
					c1[l1[k]] += 1
					c2[l1[j]] += 1
					c2[l1[k]] -= 1
					d1 = defaultdict(list)
					d2 = defaultdict(list)
					for p in range(n):
						d1[l1[p]].append(p)
						d2[l2[p]].append(p)
					l.append([k + 1, j + 1])
		if ans > 2 * n:
			print('No')
		else:
			print('Yes')
			print(ans)
			if len(l) > 0:
				for j in l:
					print(*j)


m = int(input())
for i in range(0, m):
	length = int(input())
	str1 = input()
	str2 = input()
	list10 = list(str1)
	list20 = list(str2)
	zz = list10[:]
	zz.extend(list20)
	nlist = []
	klist = []
	for k in zz:
		if (k in klist) == False:
			number = zz.count(k)
			nlist.append(number)
			klist.append(k)
			if number % 2 != 0:
				print('No')
				break
	if number % 2 == 0:
		print('Yes')
		operation = 0
		list1 = []
		list2 = []
		for z in range(0, length - 1):
			if str1[z] != str2[z]:
				d = str2.find(str2[z], z + 1)
				if d != -1:
					(list20[d], list10[z]) = (list10[z], list20[d])
					str1 = ''.join(list10)
					str2 = ''.join(list20)
					operation += 1
					list1.append(z + 1)
					list2.append(d + 1)
				else:
					d = str1.find(str2[z], z + 1)
					(list20[length - 1], list10[d]) = (list10[d], list20[length - 1])
					(list20[length - 1], list10[z]) = (list10[z], list20[length - 1])
					operation += 2
					str1 = ''.join(list10)
					str2 = ''.join(list20)
					list1.extend([d + 1, z + 1])
					list2.extend([length, length])
		print(operation)
		for j in range(operation):
			print(list1[j], end=' ')
			print(list2[j])


import string
results = []
for _ in range(int(input())):
	d = dict.fromkeys(string.ascii_lowercase, 0)
	input()
	s = input().rstrip('\n')
	t = input().rstrip('\n')
	ds = []
	dt = []
	diff = 0
	for i in range(len(s)):
		d[s[i]] += 1
		d[t[i]] += 1
		if s[i] != t[i]:
			diff += 1
	no = False
	for i in d.values():
		if i != 0 and i % 2 != 0:
			no = True
			break
	if no:
		results.append(False)
		continue
	resultss = []
	while diff > 0 and len(resultss) < 2 * len(s):
		for i in range(len(s)):
			if s[i] != t[i]:
				swapped = False
				for j in range(i + 1, len(s)):
					if s[j] != t[j] and s[i] == s[j] and (t[i] == t[j]):
						tmp = s[i]
						s = s[:i] + t[j] + s[i + 1:]
						t = t[:j] + tmp + t[j + 1:]
						diff -= 2
						swapped = True
						resultss.append((i + 1, j + 1))
						break
				if swapped == False:
					for j in range(i + 1, len(s)):
						if s[j] != t[j] and (s[i] == s[j] or t[i] == t[j]):
							tmp = s[i]
							s = s[:i] + t[j] + s[i + 1:]
							t = t[:j] + tmp + t[j + 1:]
							diff -= 1
							swapped = True
							resultss.append((i + 1, j + 1))
							break
				if swapped == False:
					tmp = s[i]
					s = s[:i] + t[i] + s[i + 1:]
					t = t[:i] + tmp + t[i + 1:]
					resultss.append((i + 1, i + 1))
					break
	if diff > 0:
		results.append(False)
	else:
		results.append(resultss)
for i in results:
	if i == False:
		print('No')
	else:
		print('Yes')
		print(len(i))
		for j in i:
			print(str(j[0]) + ' ' + str(j[1]))


k = int(input())
for i in range(k):
	n = int(input())
	s = input()
	t = input()
	o = s + t
	a = [0] * 26
	for j in o:
		a[ord(j) - 97] += 1
	for j in a:
		if j % 2 == 1:
			print('No')
			break
	else:
		s = list(s)
		t = list(t)
		number = 0
		ans = []
		print('Yes')
		for j in range(n):
			if s[j] != t[j]:
				check = True
				for k in range(j + 1, n):
					if t[k] == t[j]:
						number += 1
						ans.append([j + 1, k + 1])
						t[k] = s[j]
						s[j] = t[j]
						check = False
						break
				if check:
					for k in range(j + 1, n):
						if s[k] == t[j]:
							number += 2
							ans.append([j + 1, j + 1])
							ans.append([k + 1, j + 1])
							s[k] = s[j]
							s[j] = t[j]
							break
		print(number)
		for j in ans:
			print(*j)


import collections

def solve(n, s, t):
	d = collections.defaultdict(int)
	for i in range(n):
		d[s[i]] += 1
		d[t[i]] += 1
	for k in d.keys():
		if d[k] % 2 == 1:
			print('No')
			return
	swap = []
	for i in range(n):
		if s[i] == t[i]:
			continue
		for j in range(i + 1, n):
			if s[j] == s[i]:
				swap.append([j, i])
				(s[j], t[i]) = (t[i], s[j])
				break
			elif t[j] == s[i]:
				swap.append([j, j])
				swap.append([j, i])
				(s[j], t[j]) = (t[j], s[j])
				(s[j], t[i]) = (t[i], s[j])
				break
	print('Yes')
	print(len(swap))
	for (a, b) in swap:
		print(a + 1, b + 1)
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	solve(n, s, t)


k = int(input())
while k:
	k -= 1
	n = int(input())
	ss = input()
	tt = input()
	s = []
	t = []
	for i in range(n):
		s.append(ss[i])
		t.append(tt[i])
	count = 0
	ans = []
	ch = 0
	for i in range(n):
		if s[i] != t[i]:
			check = 0
			for j in range(i + 1, n):
				if s[j] == s[i]:
					count += 1
					(s[j], t[i]) = (t[i], s[j])
					ans.append([j + 1, i + 1])
					check = 1
					break
			if check == 0:
				for j in range(i + 1, n):
					if t[j] == s[i]:
						check = 1
						count += 2
						(s[j], t[j]) = (t[j], s[j])
						ans.append([j + 1, j + 1])
						(s[j], t[i]) = (t[i], s[j])
						ans.append([j + 1, i + 1])
						break
			if check == 0:
				ch = 1
				break
	if ch:
		print('No')
	elif count > 2 * n:
		print('No')
	else:
		print('Yes')
		print(count)
		for i in ans:
			print(*i)


cases = int(input())
for _ in range(cases):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	swaps = 0
	order = []
	i = 0
	while i < n and swaps < 2 * n:
		if s1[i] == s2[i]:
			i += 1
		elif i == n - 1:
			swaps = 2 * n + 1
		else:
			for j in range(i + 1, n):
				if s1[i] == s1[j]:
					(s2[i], s1[j]) = (s1[j], s2[i])
					swaps += 1
					order.append((j, i))
					break
				elif s2[i] == s2[j]:
					(s1[i], s2[j]) = (s2[j], s1[i])
					swaps += 1
					order.append((i, j))
					break
				elif j == n - 1:
					(s1[i], s2[i]) = (s2[i], s1[i])
					swaps += 1
					order.append((i, i))
	if swaps >= 2 * n:
		print('No')
	else:
		print('Yes')
		print(swaps)
		for (a, b) in order:
			print(a + 1, b + 1)


import sys
from collections import Counter, defaultdict
input = sys.stdin.readline
k = int(input())
for _ in range(k):
	n = int(input())
	s = list(input())
	t = list(input())
	ctr = Counter(s) + Counter(t)
	possible = True
	for v in ctr.values():
		if v & 1:
			possible = False
			break
	if not possible:
		print('No')
		continue
	loc_s = defaultdict(list)
	loc_t = defaultdict(list)
	for (i, c) in enumerate(s):
		loc_s[c].append(i)
	for (i, c) in enumerate(t):
		loc_t[c].append(i)
	ans = []
	for j in range(n):
		c = s[j]
		if t[j] == c:
			continue
		for i in range(j + 1, n):
			if s[i] == c:
				(s[i], t[j]) = (t[j], s[i])
				ans.append((i, j))
				break
		else:
			for i in range(j + 1, n):
				if t[i] == c:
					(s[i], t[i]) = (t[i], s[i])
					ans.append((i, i))
					(s[i], t[j]) = (t[j], s[i])
					ans.append((i, j))
					break
	print('Yes')
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)


for _ in range(int(input())):
	l = int(input())
	a = list(input())
	b = list(input())
	fCount = [0] * 26
	sCount = [0] * 26
	ans = True
	for i in range(l):
		fCount[ord(a[i]) - 97] += 1
		sCount[ord(b[i]) - 97] += 1
	for i in range(26):
		if (fCount[i] + sCount[i]) % 2 != 0:
			ans = False
			break
	if not ans:
		print('No')
		continue
	print('Yes')
	ans = []
	for i in range(l):
		if a[i] != b[i]:
			for g in range(i + 1, l):
				if a[i] == a[g]:
					(a[g], b[i]) = (b[i], a[i])
					ans.append(str(g + 1) + ' ' + str(i + 1))
					break
			else:
				for g in range(i + 1, l):
					if b[g] == a[i]:
						ans.append(str(i + 1) + ' ' + str(i + 1))
						(a[i], b[i]) = (b[i], a[i])
						ans.append(str(i + 1) + ' ' + str(g + 1))
						(a[i], b[g]) = (b[g], a[i])
	print(len(ans))
	print(*ans, sep='\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	c = dict()
	for j in range(n):
		if ord(a[j]) - 97 in c.keys():
			c[ord(a[j]) - 97] += 1
		else:
			c[ord(a[j]) - 97] = 1
		if ord(b[j]) - 97 in c.keys():
			c[ord(b[j]) - 97] += 1
		else:
			c[ord(b[j]) - 97] = 1
	p = 0
	for j in range(n):
		if c[ord(a[j]) - 97] % 2 != 0:
			p = 1
			break
		if c[ord(b[j]) - 97] % 2 != 0:
			p = 1
			break
	if p == 1:
		print('No')
	else:
		d = []
		e = []
		f = []
		for j in a:
			e.append(j)
		for j in b:
			f.append(j)
		a = e.copy()
		b = f.copy()
		for i in range(n):
			if a[i] == b[i]:
				pass
			else:
				for j in range(i + 1, n):
					if a[j] == a[i]:
						d.append([j + 1, i + 1])
						e = a[j]
						a[j] = b[i]
						b[i] = e
						break
					elif b[j] == a[i]:
						d.append([j + 1, j + 1])
						e = a[j]
						a[j] = b[j]
						b[j] = e
						d.append([j + 1, i + 1])
						e = a[j]
						a[j] = b[i]
						b[i] = e
						break
		print('Yes')
		print(len(d))
		for p in d:
			print(*p)


q = int(input())
for _ in range(q):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	f = 0
	ans = []
	for i in range(n):
		if s1[i] != s2[i]:
			for j in range(i + 1, n):
				if s2[j] == s1[i]:
					ans.append([n, j + 1])
					ans.append([n, i + 1])
					(s2[i], s2[j]) = (s2[j], s2[i])
					(s1[n - 1], s2[j]) = (s2[j], s1[n - 1])
					break
				elif s1[j] == s1[i]:
					ans.append([j + 1, i + 1])
					(s1[j], s2[i]) = (s2[i], s1[j])
					break
			else:
				f = 1
				break
	if f == 1:
		print('No')
		continue
	print('Yes')
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	d = dict()
	for j in range(n):
		if t[j] in d:
			d[t[j]] += 1
		else:
			d.update({t[j]: 1})
		if s[j] in d:
			d[s[j]] += 1
		else:
			d.update({s[j]: 1})
	f = 0
	for j in d:
		if d[j] % 2 != 0:
			f = 1
			break
	if f == 1:
		print('No')
	else:
		ans = []
		print('Yes')
		for j in range(n):
			if s[j] != t[j]:
				for k in range(j + 1, n):
					if s[k] == s[j]:
						(t[j], s[k]) = (s[k], t[j])
						ans.append([k + 1, j + 1])
						break
					elif t[k] == s[j]:
						(t[k], s[k]) = (s[k], t[k])
						ans.append([k + 1, k + 1])
						(t[j], s[k]) = (s[k], t[j])
						ans.append([k + 1, j + 1])
						break
		print(len(ans))
		for d in range(len(ans)):
			print(ans[d][0], ans[d][1])


from sys import stdin

def rl():
	return [int(w) for w in stdin.readline().split()]
(k,) = rl()
for _ in range(k):
	(n,) = rl()
	s = stdin.readline().strip()
	t = stdin.readline().strip()
	st = list(s + t)
	pos = {c: set() for c in st}
	for (i, c) in enumerate(st):
		pos[c].add(i)
	ops = []
	try:
		for i in range(n):
			c = st[i]
			c2 = st[n + i]
			pos[c].remove(i)
			if c == c2:
				pos[c].remove(n + i)
				continue
			j = pos[c].pop()
			st[j] = c2
			pos[c2].remove(n + i)
			pos[c2].add(j)
			if j < n:
				ops.append('%d %d' % (j + 1, i + 1))
			else:
				ops.append('%d %d' % (i + 1, i + 1))
				ops.append('%d %d' % (i + 1, j + 1 - n))
		print('Yes')
		print(len(ops))
		for op in ops:
			print(op)
	except KeyError:
		print('No')


from collections import defaultdict

def main():

	def swap(si, ti):
		temp = s[si]
		s[si] = t[ti]
		t[ti] = temp
	k = int(input())
	allans = []
	for _ in range(k):
		n = int(input())
		s = input()
		t = input()
		cnts = defaultdict(lambda : 0)
		for c in s:
			cnts[c] += 1
		for c in t:
			cnts[c] += 1
		ok = True
		for cnt in cnts.values():
			if cnt % 2 == 1:
				allans.append(['No'])
				ok = False
				break
		if ok == False:
			continue
		s = list(s)
		t = list(t)
		sequence = []
		for i in range(n - 1):
			if s[i] == t[i]:
				continue
			ok = False
			for j in range(i + 1, n):
				if s[j] == s[i]:
					sequence.append([j, i])
					swap(j, i)
					ok = True
					break
			if ok:
				continue
			for j in range(i + 1, n):
				if t[j] == s[i]:
					sequence.append([i + 1, j])
					sequence.append([i + 1, i])
					swap(i + 1, j)
					swap(i + 1, i)
					break
		m = len(sequence)
		assert m <= 2 * n
		assert s == t
		allans.append(['Yes'])
		allans.append([m])
		for (i, j) in sequence:
			allans.append([i + 1, j + 1])
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


from collections import *
for _ in range(int(input())):
	n = int(input())
	A = list(input())
	B = list(input())
	swap = []
	ans = True
	C = Counter(A + B)
	for c in C:
		ans = ans and (not C[c] % 2)
	if not ans:
		print('No')
		continue
	for i in range(n):
		if A[i] == B[i]:
			continue
		for j in range(i + 1, n):
			if A[i] == A[j]:
				swap.append((j + 1, i + 1))
				(B[i], A[j]) = (A[j], B[i])
				break
			if A[i] == B[j]:
				swap.append((j + 1, j + 1))
				swap.append((j + 1, i + 1))
				(B[i], B[j], A[j]) = (B[j], A[j], B[i])
				break
	print('Yes')
	print(len(swap))
	for i in swap:
		print(str(i[0]) + ' ' + str(i[1]))


for _ in range(int(input())):
	n = int(input())
	na = list(input())
	nb = list(input())
	k = 0
	zz = len(na)
	ans = []
	for i in range(zz):
		f = 0
		if na[i] == nb[i]:
			f = 1
		if not f:
			for j in range(i + 1, zz):
				if na[j] == na[i]:
					ans.append((j + 1, i + 1))
					na[j] = nb[i]
					f = 1
					break
		if not f:
			for j in range(i + 1, zz):
				if na[i] == nb[j]:
					ans.append((j + 1, j + 1))
					ans.append((j + 1, i + 1))
					nb[j] = na[j]
					na[j] = nb[i]
					f = 1
					break
		if not f:
			k = 1
			break
	if k:
		print('NO')
	else:
		print('YES')
		print(len(ans))
		for t in ans:
			print(t[0], t[1])


import os, sys
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
for _ in range(rint()):
	(n, s, t, mem) = (rint(), list(rstr()), list(rstr()), [0] * 26)
	for i in range(n):
		mem[ord(s[i]) - 97] += 1
		mem[ord(t[i]) - 97] += 1
	if any([x & 1 for x in mem]):
		print('No')
	else:
		print('Yes')
		out = []
		for i in range(n):
			if s[i] != t[i]:
				try:
					ix = t[i + 1:].index(t[i]) + i + 1
					(s[i], t[ix]) = (t[ix], s[i])
					out.append(f'{i + 1} {ix + 1}')
				except:
					ix = s[i + 1:].index(t[i]) + i + 1
					(s[ix], t[n - 1]) = (t[n - 1], s[ix])
					(s[i], t[n - 1]) = (t[n - 1], s[i])
					out.extend([f'{ix + 1} {n}', f'{i + 1} {n}'])
		print(len(out), *out, sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	ans = []
	for i in range(n):
		if s[i] != t[i]:
			for j in range(i + 1, n):
				if s[i] == s[j]:
					ans.append([j + 1, i + 1])
					(t[i], s[j]) = (s[j], t[i])
					break
				elif s[i] == t[j]:
					ans.append([j + 1, j + 1])
					(s[j], t[j]) = (t[j], s[j])
					ans.append([j + 1, i + 1])
					(t[i], s[j]) = (s[j], t[i])
					break
	flag = True
	for i in range(n):
		if s[i] != t[i]:
			flag = False
			print('No')
			break
	if flag:
		pp = len(ans)
		print('Yes')
		print(pp)
		for i in range(pp):
			print(*ans[i])


k = int(input())
for tt in range(k):
	n = int(input())
	s = input().strip()
	t = input().strip()
	f = [0] * 26
	arr = []
	brr = []
	for i in s:
		arr.append(i)
	for i in t:
		brr.append(i)
	pos1 = []
	pos2 = []
	for i in range(len(s)):
		if s[i] != t[i]:
			pos1.append(i)
			pos2.append(i)
			f[ord(s[i]) - ord('a')] += 1
			f[ord(t[i]) - ord('a')] += 1
	flag = True
	for i in range(26):
		if f[i] % 2 == 1:
			flag = False
			break
	if not flag:
		print('No')
		continue
	ans = []
	i = 0
	j = 0
	while i < len(pos1) and j < len(pos2):
		fl = False
		for ii in range(i + 1, len(pos1)):
			if arr[pos1[i]] == arr[pos1[ii]]:
				ans.append([pos1[ii], pos2[j]])
				temp = arr[pos1[ii]]
				arr[pos1[ii]] = brr[pos2[j]]
				brr[pos2[j]] = temp
				fl = True
				break
		if fl:
			i += 1
			j += 1
			continue
		for ii in range(j + 1, len(pos2)):
			if brr[pos2[j]] == brr[pos2[ii]]:
				ans.append([pos1[i], pos2[ii]])
				temp = arr[pos1[i]]
				arr[pos1[i]] = brr[pos2[ii]]
				brr[pos2[ii]] = temp
				fl = True
				break
		if fl:
			i += 1
			j += 1
			continue
		ans.append([pos1[i], pos2[j]])
		temp = arr[pos1[i]]
		arr[pos1[i]] = brr[pos2[j]]
		brr[pos2[j]] = temp
		fl = False
		for jj in range(j + 1, len(pos2)):
			if brr[pos2[jj]] == brr[pos2[j]]:
				temp = brr[pos2[jj]]
				brr[pos2[jj]] = arr[pos1[i]]
				arr[pos1[i]] = temp
				ans.append([pos1[i], pos2[jj]])
				fl = True
				break
		if not fl:
			ans.pop()
			temp = arr[pos1[i]]
			arr[pos1[i]] = brr[pos2[j]]
			brr[pos2[j]] = temp
			for jj in range(j + 1, len(pos2)):
				if brr[pos2[jj]] == brr[pos2[j]]:
					temp = brr[pos2[jj]]
					brr[pos2[jj]] = arr[pos1[i]]
					arr[pos1[i]] = temp
					ans.append([pos1[i], pos2[jj]])
					break
		i += 1
		j += 1
	fl = True
	for i in range(len(arr)):
		if arr[i] != brr[i]:
			fl = False
			break
	if not fl:
		print(s + t)
		continue
	print('Yes')
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0] + 1, ans[i][1] + 1)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	dic = {}
	flag = 0
	for i in range(n):
		if s[i] in dic:
			dic[s[i]] += 1
		else:
			dic[s[i]] = 1
		if t[i] in dic:
			dic[t[i]] += 1
		else:
			dic[t[i]] = 1
	for (key, value) in dic.items():
		if value % 2 != 0:
			flag = 1
	if flag == 1:
		print('No')
	else:
		swap = []
		i = 0
		while i < n:
			if s[i] == t[i]:
				i += 1
			else:
				for j in range(i + 1, n):
					if s[j] == s[i]:
						(t[i], s[j]) = (s[j], t[i])
						swap.append((j + 1, i + 1))
						i += 1
						break
				else:
					for j in range(i + 1, n):
						if t[j] == s[i]:
							(t[j], s[j]) = (s[j], t[j])
							swap.append((j + 1, j + 1))
							break
		if s == t and len(swap) <= 2 * n:
			print('Yes')
			print(len(swap))
			for (x, y) in swap:
				print(x, y)
		else:
			print('No')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	s = list(input())
	t = list(input())
	d = defaultdict(int)
	for x in s:
		d[x] += 1
	for x in t:
		d[x] += 1
	bad = False
	for key in list(d):
		if d[key] % 2:
			bad = True
	if bad:
		print('No')
		continue
	res = []
	for i in range(n):
		if s[i] != t[i]:
			if i == n - 1:
				bad = True
				break
			for j in range(i + 1, n):
				if t[i] == t[j]:
					(s[i], t[j]) = (t[j], s[i])
					res.append((i, j))
					break
			else:
				for j in range(i + 1, n):
					if t[i] == s[j]:
						(s[j], t[j]) = (t[j], s[j])
						(s[i], t[j]) = (t[j], s[i])
						res.append((j, j))
						res.append((i, j))
						break
	if bad:
		print('No')
		continue
	print('Yes')
	print(len(res))
	for (a, b) in res:
		print(a + 1, b + 1)


from __future__ import print_function
from itertools import permutations as perm
from functools import cmp_to_key
from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
ans = []

def find(ch, n, a, b, j):
	(ai, bi) = (-1, -1)
	for i in range(n):
		if i == j or a[i] == b[i]:
			continue
		if ai < 0 and a[i] == ch:
			ai = i
		elif bi < 0 and b[i] == ch:
			bi = i
	return (ai, bi)

def solve(n, a, b):
	ans.append('yes')
	mv = []
	for i in range(n):
		if a[i] != b[i]:
			(ai, bi) = find(a[i], n, a, b, i)
			if ai != -1:
				(a[ai], b[i]) = (b[i], a[ai])
				mv.append((ai + 1, i + 1))
			else:
				(a[bi], b[bi]) = (b[bi], a[bi])
				mv.append((bi + 1, bi + 1))
				(a[bi], b[i]) = (b[i], a[bi])
				mv.append((bi + 1, i + 1))
	ans.append(str(len(mv)))
	for (x, y) in mv:
		ans.append(str(x) + ' ' + str(y))
for _ in range(t):
	(n,) = gil()
	(a, b) = (gcl(), gcl())
	(fa, fb) = (Counter(a), Counter(b))
	s = 0
	for ch in 'abcdefghijklmnopqrstuvwxyz':
		(ai, bi) = (fa.get(ch, 0), fb.get(ch, 0))
		fi = (ai + bi) // 2
		s += fi
	if s == n:
		solve(n, a, b)
	else:
		ans.append('no')
print('\n'.join(ans))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	d = [0] * 26
	for i in s:
		d[ord(i) - 97] += 1
	for i in t:
		d[ord(i) - 97] += 1
	flag = 0
	for i in d:
		if i % 2:
			flag = 1
			break
	if flag:
		print('No')
	else:
		ans = []
		print('Yes')
		build = 0
		while build < n:
			if s[build] == t[build]:
				build += 1
				continue
			present = False
			for i in range(build + 1, n):
				if s[build] == s[i]:
					ans.append((i + 1, build + 1))
					(s[i], t[build]) = (t[build], s[i])
					present = True
					break
			if not present:
				findbelow = False
				for i in range(build + 1, n):
					if s[build] == t[i]:
						ans.append((build + 2, i + 1))
						ans.append((build + 2, build + 1))
						(s[build + 1], t[i]) = (t[i], s[build + 1])
						(s[build + 1], t[build]) = (t[build], s[build + 1])
						findbelow = True
						break
			build += 1
		print(len(ans))
		for i in ans:
			print(i[0], i[1])


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	a = list(inp())
	b = list(inp())
	cnt = [0] * 26
	for i in range(n):
		cnt[ord(a[i]) - 97] += 1
		cnt[ord(b[i]) - 97] += 1
	for i in range(26):
		if cnt[i] % 2 == 1:
			print('No')
			return
	print('YES')
	ans = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		ind = -1
		for ii in range(i + 1, n):
			if a[i] == a[ii]:
				ind = ii
				break
		if ind == -1:
			for ii in range(i + 1, n):
				if b[ii] == a[i]:
					ind = ii
					break
			(a[ind], b[ind]) = (b[ind], a[ind])
			(a[ind], b[i]) = (b[i], a[ind])
			ans.append((ind, ind))
			ans.append((ind, i))
		else:
			(a[ind], b[i]) = (b[i], a[ind])
			ans.append((ind, i))
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0] + 1, ans[i][1] + 1)
testcase(int(inp()))


import random

def get_int():
	return int(input())

def put_equal_on(pos, S, T, swaps):
	if S[pos] == T[pos]:
		return True
	if not S[pos] in S[pos + 1:]:
		if not S[pos] in T[pos + 1:]:
			return False
		pos2 = pos + 1 + T[pos + 1:].index(S[pos])
		(T[pos2], S[pos2]) = (S[pos2], T[pos2])
		swaps.append((pos2, pos2))
	pos2 = pos + 1 + S[pos + 1:].index(S[pos])
	(T[pos], S[pos2]) = (S[pos2], T[pos])
	swaps.append((pos2, pos))
	return True

def prog():
	N = get_int()
	S = list(input())
	T = list(input())
	swaps = []
	for i in range(N - 1):
		if not put_equal_on(i, S, T, swaps):
			break
	if S != T:
		print('No')
	else:
		print('Yes')
		print(len(swaps))
		for (a, b) in swaps:
			print(a + 1, b + 1)
q = get_int()
for _ in range(q):
	prog()


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	x = list(map(lambda x: ord(x) - 97, S()))
	y = list(map(lambda x: ord(x) - 97, S()))
	a = [[] for i in range(26)]
	b = [[] for i in range(26)]
	v = [0] * 26
	for i in range(n):
		v[x[i]] += 1
		v[y[i]] += 1
		a[x[i]] += (i,)
		b[y[i]] += (i,)
	if 1 in [i & 1 for i in v]:
		print('No')
		continue
	ans = []
	for i in range(n):
		a[x[i]].remove(i)
		b[y[i]].remove(i)
		if x[i] != y[i]:
			if a[x[i]]:
				mn = min(a[x[i]])
				a[x[i]].remove(mn)
				ans += ((mn + 1, i + 1),)
				a[y[i]] += (mn,)
				(x[mn], y[i]) = (y[i], x[mn])
			else:
				ans += ((i + 1, i + 1),)
				mn = min(b[x[i]])
				b[x[i]].remove(mn)
				ans += ((i + 1, mn + 1),)
				b[y[i]] += (mn,)
				(y[mn], y[i]) = (y[i], y[mn])
	print('Yes')
	print(len(ans))
	for i in ans:
		print(*i)


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def primeFactorsCount(n):
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt += 1
			n = n // i
	if n > 2:
		cnt += 1
	return cnt

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

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

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def getXor(n):
	xor = 1
	for i in range(2, n + 1):
		xor = xor ^ i
	return xor
for xyz in range(0, int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	cnt = [0] * 26
	for i in range(0, n):
		cnt[ord(s1[i]) - 97] += 1
		cnt[ord(s2[i]) - 97] += 1
	f = True
	for i in cnt:
		if i % 2:
			f = False
			break
	if f:
		print('Yes')
		ans = []
		(s1, s2) = (list(s1), list(s2))
		for i in range(0, n):
			if s1[i] != s2[i]:
				if s1[i] in s1[i + 1:]:
					pos = s1[i + 1:].index(s1[i]) + i + 1
					ans.append([pos + 1, i + 1])
					(s1[pos], s2[i]) = (s2[i], s1[pos])
				else:
					pos = s2[i + 1:].index(s1[i]) + i + 1
					ans.append([pos + 1, pos + 1])
					(s1[pos], s2[pos]) = (s2[pos], s1[pos])
					ans.append([pos + 1, i + 1])
					(s1[pos], s2[i]) = (s2[i], s1[pos])
		print(len(ans))
		for i in ans:
			print(*i)
	else:
		print('No')


from collections import defaultdict

def solve():
	n = int(input())
	s = input().strip()
	t = input().strip()
	lcount = defaultdict(int)
	for letter in s + t:
		lcount[letter] += 1
	possible = all((c % 2 == 0 for c in lcount.values()))
	if not possible:
		print('No')
	else:
		print('Yes')
		swaps = list()
		s = list(s)
		t = list(t)
		sletters = defaultdict(list)
		for (pos, letter) in enumerate(s):
			sletters[letter].append(pos)
		tletters = defaultdict(list)
		for (pos, letter) in enumerate(t):
			tletters[letter].append(pos)

		def swap(i, j):
			swaps.append((i, j))
			temp = s[i]
			s[i] = t[j]
			t[j] = temp
			sletters[temp].remove(i)
			sletters[s[i]].append(i)
			tletters[s[i]].remove(j)
			tletters[temp].append(j)
		alphabet = 'abcdefghijklmnopqrstuvwxyz'
		remove_from_s = []
		remove_from_t = []
		for letter in alphabet:
			remove_from_s.extend(sletters[letter][lcount[letter] // 2:])
			remove_from_t.extend(tletters[letter][lcount[letter] // 2:])
		for (i, j) in zip(remove_from_s, remove_from_t):
			swap(i, j)
		target = s
		positions_to_fix = [pos for pos in range(n) if t[pos] != target[pos]]
		destinations = []
		for pos in positions_to_fix:
			possible_destinations = [p for p in positions_to_fix if target[p] == t[pos] and p not in destinations]
			destinations.append(possible_destinations[0])
		destination_map = dict()
		for (pos, dest) in zip(positions_to_fix, destinations):
			destination_map[pos] = dest
		pivot_contents = None
		while len(positions_to_fix) > 0:
			if pivot_contents == None:
				pos = positions_to_fix[0]
				swap(0, pos)
				pivot_contents = pos
			else:
				dest = destination_map[pivot_contents]
				swap(0, dest)
				positions_to_fix.remove(pivot_contents)
				if dest in positions_to_fix:
					pivot_contents = dest
				else:
					pivot_contents = None
		print(len(swaps))
		for (i, j) in swaps:
			print('%d %d' % (i + 1, j + 1))
k = int(input())
for i in range(k):
	solve()


import sys
for t in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	s1 = [ord(c) - 97 for c in sys.stdin.readline().strip()]
	s2 = [ord(c) - 97 for c in sys.stdin.readline().strip()]
	pl = []
	orde = True
	for i in range(26):
		st1 = {j for j in range(n) if s1[j] == i}
		st2 = {j for j in range(n) if s2[j] == i}
		if len(st2) > len(st1):
			(st1, st2) = (st2, st1)
			(s1, s2) = (s2, s1)
			orde = not orde
		rml = []
		for el in st2:
			if el in st1:
				rml.append(el)
		for el in rml:
			st1.remove(el)
			st2.remove(el)
		tot = len(st1) + len(st2)
		if tot & 1:
			pl = []
			break
		for k in st2:
			st1.add(k)
			pl.append((k, k))
			(s1[k], s2[k]) = (s2[k], s1[k])
		for j in range(tot // 2):
			k1 = st1.pop()
			k2 = st1.pop()
			pl.append((k1, k2) if orde else (k2, k1))
			(s1[k1], s2[k2]) = (s2[k2], s1[k1])
	if pl == []:
		print('No')
	else:
		print(f'Yes\n{len(pl)}\n' + ''.join([f'{tup[0] + 1} {tup[1] + 1}\n' for tup in pl]))


k = int(input())
for nt in range(k):
	n = int(input())
	s = input()
	t = input()
	count = {}
	for i in range(n):
		if s[i] in count:
			count[s[i]] += 1
		else:
			count[s[i]] = 1
		if t[i] in count:
			count[t[i]] += 1
		else:
			count[t[i]] = 1
	flag = 0
	for i in count:
		if count[i] % 2 == 1:
			flag = 1
			print('No')
			break
	if flag == 1:
		continue
	print('Yes')
	ans = []
	for i in range(n - 1):
		if s[i] != t[i]:
			place = t.find(s[i], i + 1)
			if place != -1:
				ans.append([i + 2, place + 1])
				ans.append([i + 2, i + 1])
				ex = s[i + 1]
				s = s[0:i + 1] + t[i] + s[i + 2:]
				t = t[0:i] + t[place] + t[i + 1:place] + ex + t[place + 1:]
			else:
				place = s.find(s[i], i + 1)
				ans.append([place + 1, i + 1])
				s = s[0:place] + t[i] + s[place + 1:]
				t = t[0:i] + s[i] + t[i + 1:]
	print(len(ans))
	for i in ans:
		print(*i)


def swap(i, j):
	global st, tt
	xx = st[i]
	st[i] = tt[j]
	tt[j] = xx
for _ in range(int(input())):
	n = int(input())
	st = list(input())
	tt = list(input())
	dic = {}
	for i in st:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	for i in tt:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	flag = True
	for i in dic:
		if dic[i] % 2 != 0:
			flag = False
	if flag:
		print('Yes')
		ans = 0
		li = []
		for i in range(n):
			if st[i] != tt[i]:
				for j in range(i + 1, n):
					if st[j] == st[i]:
						ans += 1
						li.append([j + 1, i + 1])
						swap(j, i)
						break
					elif st[i] == tt[j]:
						ans += 2
						li.append([j + 1, j + 1])
						swap(j, j)
						li.append([j + 1, i + 1])
						swap(j, i)
						break
		print(ans)
		for i in li:
			print(*i)
	else:
		print('No')


k = int(input())
for i in range(k):
	n = int(input())
	s = input()
	t = input()
	s1 = list(s)
	t1 = list(t)
	arr = []

	def func(s, t, j, arr):
		if s1[j] != t1[j]:
			flag = False
			for l in range(j + 1, n):
				if s1[l] == s1[j]:
					flag = True
					break
			if flag == True:
				(s1[l], t1[j]) = (t1[j], s1[l])
				arr.append(str(l + 1) + ' ' + str(j + 1))
			else:
				for l in range(j + 1, n):
					if t1[l] == s1[j]:
						break
				(s1[j + 1], t1[l]) = (t1[l], s1[j + 1])
				arr.append(str(j + 2) + ' ' + str(l + 1))
				(s1[j + 1], t1[j]) = (t1[j], s1[j + 1])
				arr.append(str(j + 2) + ' ' + str(j + 1))
	dic = {}
	for j in s:
		if j not in dic:
			dic[j] = 1
		else:
			dic[j] += 1
	for j in t:
		if j not in dic:
			dic[j] = 1
		else:
			dic[j] += 1
	flag = False
	for j in dic:
		if dic[j] % 2 != 0:
			flag = True
			break
	if flag == True:
		print('No')
	else:
		for j in range(0, n - 1):
			func(s, t, j, arr)
		print('Yes')
		print(len(arr))
		for j in arr:
			print(j)


from collections import Counter
k = int(input())
for i in range(k):
	n = int(input())
	s = input()
	t = input()
	c = Counter(s + t)
	f = False
	for key in c:
		if c[key] % 2 != 0:
			print('No')
			f = True
			break
	if f:
		continue
	else:
		print('Yes')
	op = []
	for i in range(n):
		if s[i] == t[i]:
			continue
		f = True
		if t[i] in t[i + 1:]:
			idx = t[i + 1:].index(t[i]) + i + 1
			op.append((i + 1, idx + 1))
			(s, t) = (s[:i] + t[idx] + s[i + 1:], t[:idx] + s[i] + t[idx + 1:])
		else:
			idx = s[i + 1:].index(t[i]) + i + 1
			op.append((idx + 1, i + 1 + 1))
			op.append((i + 1, i + 1 + 1))
			(s, t) = (s[:idx] + t[i + 1] + s[idx + 1:], t[:i + 1] + s[idx] + t[i + 2:])
			(s, t) = (s[:i] + t[i + 1] + s[i + 1:], t[:i + 1] + s[i] + t[i + 2:])
	if not f:
		print('1')
		print('1 1')
	else:
		print(len(op))
		for sw in op:
			print(*sw)


def main():
	global visited, adj, sets
	n = get_int()
	s1 = list(input())
	s2 = list(input())
	swaps = []

	def swp(s1_ptr, s2_ptr):
		swaps.append([s1_ptr + 1, s2_ptr + 1])
		(s1[s1_ptr], s2[s2_ptr]) = (s2[s2_ptr], s1[s1_ptr])
	for i in range(n):
		if s1[i] != s2[i]:
			fixed = False
			for j in range(i + 1, n):
				if s1[j] == s1[i]:
					swp(j, i)
					fixed = True
					break
			if not fixed:
				for j in range(i + 1, n):
					if s1[i] == s2[j]:
						swp(j, j)
						swp(j, i)
						break
	if s1 == s2:
		print('YES')
		print(len(swaps))
		[print(' '.join(map(str, x))) for x in swaps]
	else:
		print('NO')
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


import collections
k = int(input())
for kk in range(k):
	n = int(input())
	s = list(input())
	t = list(input())
	operations = list()
	for i in range(n):
		if s[i] != t[i]:
			ok = False
			for j in range(i + 1, n):
				if s[i] == s[j]:
					ok = True
					operations.append((j, i))
					(s[j], t[i]) = (t[i], s[j])
					break
				if s[i] == t[j] and i + 1 < n:
					ok = True
					operations.append((i + 1, j))
					(t[j], s[i + 1]) = (s[i + 1], t[j])
					operations.append((i + 1, i))
					(s[i + 1], t[i]) = (t[i], s[i + 1])
					break
			if not ok:
				operations = None
				break
	if operations is None:
		print('No')
	else:
		assert s == t
		print('Yes')
		print(len(operations))
		for (i, j) in operations:
			print(1 + i, 1 + j)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input().rstrip())
	t = list(input().rstrip())
	cnt = [0] * 26
	ans = []
	for i in range(n):
		if s[i] != t[i]:
			for j in range(i + 1, n):
				if s[i] == s[j]:
					ans.append((j, i))
					(t[i], s[j]) = (s[j], t[i])
					break
			else:
				for j in range(i + 1, n):
					if s[i] == t[j]:
						ans.append((j, j))
						(t[j], s[j]) = (s[j], t[j])
						ans.append((j, i))
						(t[i], s[j]) = (s[j], t[i])
						break
	if ''.join(s) == ''.join(t):
		print('Yes')
		print(len(ans))
		for (x, y) in ans:
			print(x + 1, y + 1)
	else:
		print('No')


import sys
input = sys.stdin.readline
from bisect import *
t = int(input())
for _ in range(t):
	n = int(input())
	(s1, s2) = (list(input().strip()), list(input().strip()))
	opr = []
	g = 0
	for i in range(n):
		if s1[i] == s2[i]:
			continue
		a = i
		e = 0
		if s1[a] in s1[a + 1:]:
			b = s1[a + 1:].index(s1[a]) + a + 1
			(s2[a], s1[b]) = (s1[b], s2[a])
			opr.append((b + 1, a + 1))
		elif s1[a] in s2[a + 1:]:
			b = s2[a + 1:].index(s1[a]) + a + 1
			(s1[a], s2[a]) = (s2[a], s1[a])
			(s1[a], s2[b]) = (s2[b], s1[a])
			opr.append((a + 1, a + 1))
			opr.append((a + 1, b + 1))
		elif s2[a] in s2[a + 1:]:
			b = s2[a + 1:].index(s2[a]) + a + 1
			(s1[a], s2[b]) = (s2[b], s1[a])
			opr.append((a + 1, b + 1))
		elif s2[a] in s1[a + 1:]:
			b = s1[a + 1:].index(s2[a]) + a + 1
			(s2[a], s1[a]) = (s1[a], s2[a])
			(s2[a], s1[b]) = (s1[b], s2[a])
			opr.append((a + 1, a + 1))
			opr.append((b + 1, a + 1))
		else:
			g = 1
			break
	if g:
		print('NO')
	else:
		print('YES')
		print(len(opr))
		for i in opr:
			print(*i)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	cc = {}
	for c in s:
		cc[c] = cc.get(c, 0) + 1
	for c in t:
		cc[c] = cc.get(c, 0) + 1
	for (c, v) in cc.items():
		if v % 2:
			print('No')
			break
	else:
		print('Yes')
		swaps = []
		for i in range(n):
			if s[i] != t[i]:
				for j in range(i + 1, n):
					if t[j] == s[i]:
						swaps.append((j + 1, j + 1))
						(s[j], t[j]) = (t[j], s[j])
						break
				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])
						break
		print(len(swaps))
		for s in swaps:
			print(*s)


from collections import Counter, deque
import sys
import math
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())
for _ in range(val()):
	n = val()
	s1 = st()
	s2 = st()
	cnt = Counter(s1) + Counter(s2)
	ans = 'YES'
	for i in cnt:
		if cnt[i] & 1:
			ans = 'NO'
			break
	print(ans)
	if ans[0] == 'N':
		continue
	s1 = list(s1)
	s2 = list(s2)
	ans = []
	for i in range(len(s1)):
		if s1[i] != s2[i]:
			curr = 0
			for j in range(i + 1, len(s1)):
				if s1[j] == s1[i]:
					s1[j] = s2[i]
					ans.append([j, i])
					curr = 1
					break
			if curr:
				continue
			for j in range(i + 1, len(s2)):
				if s2[j] == s1[i]:
					ans.append([j, j])
					ans.append([j, i])
					(s1[j], s2[j]) = (s2[j], s1[j])
					s1[j] = s2[i]
					curr = 1
					break
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1)


import sys

def get(s, t):
	arr = [0] * 26
	ans = []
	n = len(s)
	for i in range(n):
		arr[ord(s[i]) - 97] += 1
		arr[ord(t[i]) - 97] += 1
	for i in range(26):
		if arr[i] % 2 != 0:
			return False
	for i in range(n):
		if s[i] == t[i]:
			pass
		else:
			z = True
			for k in range(i + 1, n):
				if s[k] == s[i]:
					z = False
					break
			if not z:
				(t[i], s[k]) = (s[k], t[i])
				ans.append([k, i])
				continue
			for k in range(i + 1, n):
				if t[k] == s[i]:
					z = False
					break
			if not z:
				ans.append([n - 1, k])
				(s[n - 1], t[k]) = (t[k], s[n - 1])
				ans.append([n - 1, i])
				(s[n - 1], t[i]) = (t[i], s[n - 1])
	return ans
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = list(sys.stdin.readline())[:-1]
	t = list(sys.stdin.readline())[:-1]
	a = get(s, t)
	if a:
		print('YES')
		print(len(a))
		for i in range(len(a)):
			print(a[i][0] + 1, a[i][1] + 1)
	else:
		print('no')


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
		print('Yes')
		print(len(ans))
		for i in ans:
			print(i[0] + 1, i[1] + 1)


t = int(input())
for l in range(t):
	n = int(input())
	s = list(input())
	k = list(input())
	i = 0
	swap = 0
	ans = list()
	flag2 = False
	while i < n and swap <= 2 * n and (not flag2):
		if s[i] == k[i]:
			i += 1
		else:
			flag = True
			for j in range(i + 1, n):
				if s[j] == s[i]:
					omg = k[i]
					k[i] = s[j]
					s[j] = omg
					ans.append([j + 1, i + 1])
					i += 1
					swap += 1
					flag = False
					break
			if flag:
				for j in range(i + 1, n):
					if s[i] == k[j]:
						omg = k[j]
						k[j] = s[-1]
						s[-1] = omg
						ans.append([n, j + 1])
						omg = k[i]
						k[i] = s[-1]
						s[-1] = omg
						ans.append([n, i + 1])
						swap += 2
						i += 1
						flag = False
			if flag:
				flag2 = True
	if flag2:
		print('NO')
	elif swap >= 2 * n:
		print('NO')
	else:
		print('YES')
		print(swap)
		for zaw in ans:
			print(zaw[0], zaw[1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	mark = [0] * 26
	for i in range(n):
		mark[ord(s[i]) - 97] += 1
		mark[ord(t[i]) - 97] += 1
	flag = False
	for num in mark:
		if num % 2 == 1:
			flag = True
			break
	if flag:
		print('No')
		continue
	ss = []
	tt = []
	for i in range(n):
		ss.append(s[i])
		tt.append(t[i])
	ans = []
	for i in range(n):
		if ss[i] != tt[i]:
			flag = True
			for j in range(i + 1, n):
				if ss[j] == ss[i]:
					flag = False
					temp = ss[j]
					ss[j] = tt[i]
					tt[i] = temp
					ans.append((j, i))
					break
			if flag:
				for j in range(i + 1, n):
					if ss[i] == tt[j]:
						temp = tt[j]
						tt[j] = ss[j]
						ss[j] = temp
						ans.append((j, j))
						temp = ss[j]
						ss[j] = tt[i]
						tt[i] = temp
						ans.append((j, i))
						break
	print('Yes')
	print(len(ans))
	for tup in ans:
		print(tup[0] + 1, tup[1] + 1)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	seq = []
	for i in range(0, n):
		if a[i] == b[i]:
			continue
		found = 0
		for j in range(i + 1, n):
			if a[j] == a[i]:
				found = 1
				seq += [str(j + 1) + ' ' + str(i + 1)]
				t = b[i]
				b = b[:i] + a[j] + b[i + 1:]
				a = a[:j] + t + a[j + 1:]
				break
		if found == 1:
			continue
		for j in range(i + 1, n):
			if b[j] == a[i]:
				seq += [str(j + 1) + ' ' + str(j + 1)]
				found = 1
				t = a[j]
				a = a[:j] + b[j] + a[j + 1:]
				b = b[:j] + t + b[j + 1:]
				seq += [str(j + 1) + ' ' + str(i + 1)]
				t = b[i]
				b = b[:i] + a[j] + b[i + 1:]
				a = a[:j] + t + a[j + 1:]
				break
		if found == 1:
			continue
		break
	if a == b:
		print('Yes')
		print(len(seq))
		for j in seq:
			print(j)
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	d = {}
	for i in range(ord('a'), ord('z') + 1):
		d[chr(i)] = 0
	for cs in s:
		d[cs] += 1
	for ct in t:
		d[ct] += 1
	ok = True
	for e in d:
		if d[e] % 2 == 1:
			ok = False
	if not ok:
		print('No')
	else:
		print('Yes')
		changes = []
		(s, t) = (list(s), list(t))
		for i in range(n - 1):
			if s[i] != t[i]:
				r = (0, -1)
				for j in range(i + 1, n):
					if s[j] == t[i]:
						r = (j, 0)
				for j in range(i + 1, n):
					if t[j] == t[i]:
						r = (j, 1)
				if r[1] == 0:
					changes += [(r[0], i + 1), (i, i + 1)]
					(s[r[0]], t[i + 1]) = (t[i + 1], s[r[0]])
					(s[i], t[i + 1]) = (t[i + 1], s[i])
				elif r[1] == 1:
					changes += [(i, r[0])]
					(s[i], t[r[0]]) = (t[r[0]], s[i])
		print(len(changes))
		for change in changes:
			(x, y) = change
			print(x + 1, y + 1)


from collections import Counter
k = int(input())
for _ in range(k):
	n = int(input())
	A = list(input())
	B = list(input())
	C = Counter(A + B)
	ans = True
	for c in C:
		ans = ans and (not C[c] % 2)
	if not ans:
		print('No')
		continue
	swaps = []
	for i in range(n):
		if A[i] == B[i]:
			continue
		for j in range(i + 1, n):
			if A[i] == A[j]:
				swaps.append((j + 1, i + 1))
				(B[i], A[j]) = (A[j], B[i])
				break
			elif A[i] == B[j]:
				swaps.append((j + 1, j + 1))
				(A[j], B[j]) = (B[j], A[j])
				swaps.append((j + 1, i + 1))
				(B[i], A[j]) = (A[j], B[i])
				break
	print('Yes')
	print(len(swaps))
	for x in swaps:
		print(*x)


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	s1 = [i for i in s1]
	s2 = [i for i in s2]
	freq = {}
	for i in s1:
		if i not in freq:
			freq[i] = 0
		freq[i] += 1
	for i in s2:
		if i not in freq:
			freq[i] = 0
		freq[i] += 1
	f = True
	for i in freq:
		if freq[i] % 2 != 0:
			f = False
			print('No')
			break
	if not f:
		continue
	pos = 0
	ans = []
	f = True
	while pos < len(s1):
		if s1[pos] == s2[pos]:
			pos += 1
			continue
		idx = -1
		for i in range(pos + 1, len(s1)):
			if s1[pos] == s1[i]:
				idx = i
				break
		if idx != -1:
			(s2[pos], s1[idx]) = (s1[idx], s2[pos])
			ans.append((idx + 1, pos + 1))
			pos += 1
			continue
		(s1[pos], s2[pos]) = (s2[pos], s1[pos])
		ans.append((pos + 1, pos + 1))
		idx = -1
		for i in range(pos + 1, len(s1)):
			if s1[pos] == s1[i]:
				idx = i
				break
		if idx != -1:
			(s2[pos], s1[idx]) = (s1[idx], s2[pos])
			ans.append((idx + 1, pos + 1))
			pos += 1
			continue
		(s1[pos], s2[pos]) = (s2[pos], s1[pos])
		ans.pop()
		idx = -1
		for i in range(pos + 1, len(s2)):
			if s2[i] == s2[pos]:
				idx = i
				break
		if idx == -1:
			f = False
			break
		(s1[pos], s2[idx]) = (s2[idx], s1[pos])
		ans.append([pos + 1, idx + 1])
	if f:
		print('Yes')
		print(len(ans))
		for i in ans:
			print(i[0], i[1])
	else:
		print('No')


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = input()
	t = input()
	pos = [0] * 26
	flag = 0
	for i in range(0, len(s)):
		pos[ord(s[i]) - 97] += 1
	for i in range(0, len(t)):
		pos[ord(t[i]) - 97] += 1
	for i in range(26):
		if pos[i] % 2 != 0:
			flag = 1
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')
		ans = []
		s1 = []
		s2 = []
		for i in range(0, len(s)):
			s1.append(s[i])
		for i in range(0, len(t)):
			s2.append(t[i])
		for i in range(0, len(s1)):
			if s1[i] != s2[i]:
				for j in range(i + 1, len(s2)):
					if s1[i] == s2[j]:
						temp = s2[j]
						s2[j] = s1[j]
						s1[j] = temp
						ans.append((j + 1, j + 1))
					if s1[i] == s1[j]:
						temp = s1[j]
						s1[j] = s2[i]
						s2[i] = temp
						ans.append((j + 1, i + 1))
						break
		print(len(ans))
		for i in ans:
			print(i[0], i[1])


from sys import stdin, stdout
from collections import Counter, deque
from bisect import bisect_left
from itertools import product
T = int(input())
for _ in range(T):
	n = int(input())
	(a, b) = (list(input()), list(input()))
	cc = Counter(a + b)
	if any([u % 2 for u in cc.values()]):
		print('No')
		continue
	res = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		if a[i] in a[i + 1:]:
			p = a[i + 1:].index(a[i])
			(b[i], a[i + p + 1]) = (a[i + p + 1], b[i])
			res.append((i + p + 1, i))
		else:
			p = b[i + 1:].index(a[i])
			(a[i + 1], b[i + p + 1]) = (b[i + p + 1], a[i + 1])
			(a[i + 1], b[i]) = (b[i], a[i + 1])
			res.append((i + 1, i + p + 1))
			res.append((i + 1, i))
	print('Yes')
	print(len(res))
	for (u, v) in res:
		print(str(u + 1) + ' ' + str(v + 1))


T = int(input())
for t in range(T):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	freq = [0] * 26
	for i in s1:
		freq[ord(i) - ord('a')] += 1
	for i in s2:
		freq[ord(i) - ord('a')] += 1
	ok = 1
	for i in range(26):
		if freq[i] & 1:
			ok = 0
	if ok == 0:
		print('No')
		continue
	freqa = [0] * 26
	mapa = [[] for i in range(26)]
	mapb = [[] for i in range(26)]
	for i in range(n):
		mapa[ord(s1[i]) - ord('a')].append(i)
		mapb[ord(s2[i]) - ord('a')].append(i)
	excessa = [[] for i in range(26)]
	excessb = [[] for i in range(26)]
	for i in range(26):
		if len(mapa[i]) > freq[i] // 2:
			for j in range(freq[i] // 2, len(mapa[i])):
				excessa[i].append(mapa[i][j])
		if len(mapb[i]) > freq[i] // 2:
			for j in range(freq[i] // 2, len(mapb[i])):
				excessb[i].append(mapb[i][j])
	alla = []
	for i in range(26):
		for j in excessa[i]:
			alla.append(j)
	allb = []
	for i in range(26):
		for j in excessb[i]:
			allb.append(j)
	op = []
	for ite in range(n):
		for i in range(n):
			if s1[i] == s2[i]:
				continue
			found = 0
			if found == 0:
				for j in range(i + 1, n):
					if s2[i] == s2[j]:
						found = 1
						op.append((i + 1, j + 1))
						(s1[i], s2[j]) = (s2[j], s1[i])
					if found:
						break
			for j in range(i - 1, -1, -1):
				if s1[j] == s2[i] and s1[j] != s2[j]:
					found = 1
					op.append((j + 1, j + 1))
					(s1[j], s2[j]) = (s2[j], s1[j])
					op.append((j + 1, i + 1))
					(s1[j], s2[i]) = (s2[i], s1[j])
				if found:
					break
	if s1 == s2:
		print('Yes')
		print(min(2 * n, len(op)))
		for i in op:
			print(*i)
	else:
		print('No')


from collections import Counter
for i in range(int(input())):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	C = Counter(s1 + s2)
	f = False
	for i in C:
		if C[i] % 2 == 1:
			f = True
			break
	if f:
		print('No')
		continue
	ans = []
	for i in range(n):
		if s1[i] == s2[i]:
			continue
		for j in range(i + 1, n):
			if s1[i] == s1[j]:
				(s2[i], s1[j]) = (s1[j], s2[i])
				ans.append((j + 1, i + 1))
				break
			if s1[i] == s2[j]:
				ans.append((j + 1, j + 1))
				(s1[j], s2[j]) = (s2[j], s1[j])
				ans.append((j + 1, i + 1))
				(s2[i], s1[j]) = (s1[j], s2[i])
				break
	print('Yes')
	print(len(ans))
	for i in ans:
		print(*i)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def seive():
	prime = [1 for i in range(10 ** 6 + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(10 ** 6 + 1):
		if prime[i]:
			for j in range(2 * i, 10 ** 6 + 1, i):
				prime[j] = 0
for _ in range(l()[0]):
	n = l()[0]
	s = list(input())
	t = list(input())
	ans = []
	i = 0
	for i in range(n):
		if s[i] == t[i]:
			continue
		for j in range(i + 1, n):
			if s[i] == s[j]:
				(s[j], t[i]) = (t[i], s[j])
				ans.append([j + 1, i + 1])
				break
			elif s[i] == t[j]:
				(t[j], s[j]) = (s[j], t[j])
				ans.append([j + 1, j + 1])
				(s[j], t[i]) = (t[i], s[j])
				ans.append([j + 1, i + 1])
				break
	if s != t:
		print('No')
		continue
	print('Yes')
	print(len(ans))
	for x in ans:
		print(*x)


from collections import defaultdict

def case():
	n = int(input())
	s = input()
	s = [i for i in s]
	t = input()
	t = [i for i in t]
	d = defaultdict(int)
	for i in s:
		d[i] += 1
	for i in t:
		d[i] += 1
	for i in d.values():
		if i % 2:
			print('NO')
			return
	ans = []
	for i in range(n):
		flag = 0
		for j in range(i + 1, n):
			if s[i] == s[j]:
				(t[i], s[j]) = (s[j], t[i])
				ans.append([j + 1, i + 1])
				flag = 1
				break
		if flag:
			continue
		for j in range(i + 1, n):
			if s[i] == t[j]:
				(s[j], t[j]) = (t[j], s[j])
				ans.append([j + 1, j + 1])
				(t[i], s[j]) = (s[j], t[i])
				ans.append([j + 1, i + 1])
				flag = 1
				break
		if flag:
			continue
	print('YES')
	print(len(ans))
	for i in ans:
		print(*i)
for _ in range(int(input())):
	case()


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	a = ips()
	b = ips()
	ch = Counter(a) + Counter(b)
	flag = True
	for i in ch:
		if ch[i] % 2 == 0:
			pass
		else:
			flag = False
			break
	if flag:
		out('Yes')
		a = list(a)
		b = list(b)
		ans = []
		for i in range(n - 1):
			if a[i] == b[i]:
				pass
			else:
				f = True
				for j in range(i + 1, n):
					if a[j] == a[i]:
						ans.append([j + 1, i + 1])
						(b[i], a[j]) = (a[j], b[i])
						f = False
						break
				if f:
					for j in range(i + 1, n):
						if a[i] == b[j]:
							ans.append([i + 2, j + 1])
							(a[i + 1], b[j]) = (b[j], a[i + 1])
							ans.append([i + 2, i + 1])
							(a[i + 1], b[i]) = (b[i], a[i + 1])
							break
		out(len(ans))
		for i in ans:
			print(*i)
	else:
		out('No')


import sys
import bisect
import heapq
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for i in range(int(ri())):
	n = int(ri())
	s = ri()
	t = ri()
	s = [i for i in s]
	t = [i for i in t]
	se = set()
	for i in s:
		if i in se:
			se.remove(i)
		else:
			se.add(i)
	for i in t:
		if i in se:
			se.remove(i)
		else:
			se.add(i)
	if len(se) > 0:
		No()
	else:
		ans = []
		for i in range(len(s)):
			if s[i] == t[i]:
				continue
			else:
				flag = -1
				for j in range(i + 1, len(s)):
					if t[j] == s[i]:
						flag = j
						break
				if flag != -1:
					ans.append([i + 1, flag])
					ans.append([i + 1, i])
					(s[i + 1], t[flag]) = (t[flag], s[i + 1])
					(s[i + 1], t[i]) = (t[i], s[i + 1])
				else:
					for j in range(i + 1, len(s)):
						if s[j] == s[i]:
							flag = j
							break
					(s[flag], t[i]) = (t[i], s[flag])
					ans.append([flag, i])
		Yes()
		print(len(ans))
		for i in range(len(ans)):
			ans[i] = [j + 1 for j in ans[i]]
		for i in ans:
			print(*i)


Q = int(input())
dg = 10 ** 5
for __ in [0] * Q:
	n = int(input())
	s = list(input())
	t = list(input())
	res = []
	judge = True
	for i in range(n):
		p = True
		if s[i] != t[i]:
			for j in range(i + 1, n):
				if s[i] == s[j]:
					res.append(j * dg + i)
					s[j] = t[i]
					p = False
					break
			if p:
				for j in range(i + 1, n):
					if s[i] == t[j]:
						res.append(j * dg + j)
						res.append(j * dg + i)
						t[j] = s[j]
						s[j] = t[i]
						p = False
						break
			if p:
				judge = False
				break
	if judge:
		print('YES')
		print(len(res))
		for e in res:
			print(e // dg + 1, e % dg + 1)
	else:
		print('NO')


def solve(a, b):
	size = len(a)
	answer = []
	for i in range(size):
		if a[i] != b[i]:
			for j in range(i + 1, size):
				if a[j] == a[i]:
					answer.append([j + 1, i + 1])
					(b[i], a[j]) = (a[j], b[i])
					break
				elif b[j] == a[i]:
					answer.append([j + 1, j + 1])
					answer.append([j + 1, i + 1])
					(b[j], a[j]) = (a[j], b[j])
					(b[i], a[j]) = (a[j], b[i])
					break
	return answer
q = int(input())
for _ in range(q):
	n = int(input())
	s = list(input())
	t = list(input())
	char_shop = [0] * 26
	for i in range(n):
		char_shop[ord(s[i]) - 97] += 1
		char_shop[ord(t[i]) - 97] += 1
	fail = False
	for c in char_shop:
		if c % 2 != 0:
			fail = True
			break
	if fail:
		print('No')
		continue
	print('Yes')
	res = solve(s, t)
	print(len(res))
	for r in res:
		print(' '.join(map(str, r)))


from bisect import bisect_right
from collections import defaultdict
a = int(input())
for i in range(a):
	s = int(input())
	a1 = input()
	a2 = input()
	k1 = []
	k2 = []
	al = defaultdict(list)
	dl = defaultdict(list)
	for i in range(s):
		al[a1[i]].append(i)
		dl[a2[i]].append(i)
		k1.append(a1[i])
		k2.append(a2[i])
	glag = 0
	swap = []
	for i in range(s):
		if k1[i] == k2[i]:
			continue
		else:
			if len(al[k1[i]]) == 1 and len(dl[k1[i]]) == 0:
				glag = 1
				break
			flag = 0
			if len(al[k1[i]]) > 1:
				t1 = al[k1[i]]
				r = bisect_right(t1, i)
				if r < len(t1):
					index = t1[r]
					swap.append([index + 1, i + 1])
					temp = k2[i]
					k2[i] = k1[i]
					k1[index] = temp
					al = defaultdict(list)
					dl = defaultdict(list)
					for i in range(len(k1)):
						al[k1[i]].append(i)
						dl[k2[i]].append(i)
					flag = 1
			if flag == 0:
				if len(dl[k1[i]]):
					r = bisect_right(dl[k1[i]], i)
					if r < len(dl[k1[i]]):
						index = dl[k1[i]][r]
						temp = k2[i]
						k2[i] = k1[i]
						t2 = k1[index]
						k1[index] = temp
						k2[index] = t2
						swap.append([index + 1, index + 1])
						swap.append([index + 1, i + 1])
						al = defaultdict(list)
						dl = defaultdict(list)
						for i in range(len(k1)):
							al[k1[i]].append(i)
							dl[k2[i]].append(i)
						flag = 1
			if flag == 0:
				glag = 1
				break
	if glag == 1:
		print('No')
	else:
		print('Yes')
		print(len(swap))
		for i in range(len(swap)):
			print(' '.join(map(str, swap[i])))


k = int(input())
for I in range(k):
	n = int(input())
	s0 = input()
	t0 = input()
	s = [s0[i] for i in range(n)]
	t = [t0[i] for i in range(n)]
	ans = 'Yes'
	ansArr = []
	for i in range(n):
		if s[i] == t[i]:
			continue
		elif s[i] in s[i + 1:]:
			ind = s.index(s[i], i + 1, n)
			ansArr += [[ind + 1, i + 1]]
			(s[ind], t[i]) = (t[i], s[ind])
		elif s[i] in t[i + 1:]:
			ind = t.index(s[i], i + 1, n)
			ansArr += [[i + 1 + 1, ind + 1]]
			(s[i + 1], t[ind]) = (t[ind], s[i + 1])
			ansArr += [[i + 1 + 1, i + 1]]
			(s[i + 1], t[i]) = (t[i], s[i + 1])
		else:
			ans = 'No'
			break
	print(ans)
	if ans == 'Yes':
		print(len(ansArr))
		for item in ansArr:
			print(item[0], item[1])


from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import random

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
k = I()
for _ in range(k):
	flg = 'Yes'
	n = I()
	s = StoI()
	t = StoI()
	u = s + t
	c = Counter(u)
	ans = []
	for i in c.items():
		if i[1] % 2 != 0:
			flg = 'No'
			break
	print(flg)
	if flg == 'No':
		continue
	for i in range(n):
		if s[i] == t[i]:
			continue
		else:
			for j in range(n - i - 1):
				scbrk = False
				if s[i + 1 + j] == s[i]:
					(s[i + 1 + j], t[i]) = (t[i], s[i + 1 + j])
					ans.append((1 + i + 1 + j, 1 + i))
					break
				else:
					for k in range(n - i - 1):
						if t[i + 1 + j] == s[i]:
							ans.append((1 + 1 + i, 1 + i + 1 + j))
							(t[i + 1 + j], s[i + 1]) = (s[i + 1], t[i + 1 + j])
							ans.append((1 + 1 + i, 1 + i))
							(t[i], s[1 + i]) = (s[1 + i], t[i])
							scbrk = True
						break
					if scbrk == True:
						break
	show(s, t)
	if len(ans) == 0:
		ans.append((1, 1))
	f = 0
	if s != t or len(ans) > 2 * n:
		show('NG')
		f = 'NG'
	else:
		show('OK??')
	print(len(ans))
	for i in ans:
		print(*i)
	if f == 'NG':
		break


t = int(input())

def equal(s, t):
	s = [x for x in s]
	t = [x for x in t]
	ans = []
	for i in range(len(s)):
		for j in range(i + 1, len(s)):
			if s[i] == s[j]:
				(s[j], t[i]) = (t[i], s[j])
				ans.append([j + 1, i + 1])
				break
			if s[i] == t[j]:
				(s[j], t[j]) = (t[j], s[j])
				ans += [[j + 1, j + 1]]
				(s[j], t[i]) = (t[i], s[j])
				ans += [[j + 1, i + 1]]
				break
	l = len(ans)
	ans = '\n'.join(['%s %s' % (x[0], x[1]) for x in ans])
	if s == t:
		return 'YES\n%s\n%s' % (l, ans)
	else:
		return 'NO'
for i in range(t):
	l = input()
	print(equal(input(), input()))


for _ in range(int(input())):
	n = int(input())
	lis = [0] * 2
	lis[0] = list(input())
	lis[1] = list(input())
	ans = []
	gg = 0
	for i in range(n):
		a = lis[0][i]
		ind = -1
		for j in range(i + 1, n):
			if a == lis[0][j]:
				ind = j
				break
		if ind != -1:
			ans.append([ind + 1, i + 1])
			(lis[1][i], lis[0][ind]) = (lis[0][ind], lis[1][i])
		else:
			for j in range(i, n):
				if a == lis[1][j]:
					ind = j
					break
			if ind != -1:
				ans.append([n, ind + 1])
				ans.append([n, i + 1])
				(lis[1][ind], lis[0][n - 1]) = (lis[0][n - 1], lis[1][ind])
				(lis[1][i], lis[0][n - 1]) = (lis[0][n - 1], lis[1][i])
			else:
				print('No')
				gg = 1
				break
	if gg == 0:
		print('Yes')
		print(len(ans))
		for i in range(len(ans)):
			print(*ans[i])


for u in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	pos = []
	for i in range(n):
		if s[i] != t[i]:
			for j in range(i + 1, n):
				if t[i] == t[j]:
					(s[i], t[j]) = (t[j], s[i])
					pos.append([i + 1, j + 1])
					break
				elif t[i] == s[j]:
					(t[j], s[j]) = (s[j], t[j])
					pos.append([j + 1, j + 1])
					(s[i], t[j]) = (t[j], s[i])
					pos.append([i + 1, j + 1])
					break
	if s == t and len(pos) <= 2 * n:
		print('Yes')
		print(len(pos))
		for i in pos:
			print(*i)
	else:
		print('No')


k = int(input())
while k:
	n = int(input())
	s = list(map(str, input().strip()))
	t = list(map(str, input().strip()))
	cnt = [0] * 60
	for i in s:
		cnt[ord(i) - ord('a')] += 1
	for i in t:
		cnt[ord(i) - ord('a')] += 1
	flag = 0
	for i in cnt:
		if i % 2:
			print('NO')
			flag = 1
			break
	if flag:
		k -= 1
		continue
	op = []
	print('YES')
	for (i, v) in enumerate(s):
		if s[i] != t[i]:
			for j in range(i + 1, n):
				if s[j] == s[i]:
					op.append((j + 1, i + 1))
					s[j] = t[i]
					break
				if t[j] == s[i]:
					op.append((n, j + 1))
					op.append((n, i + 1))
					tmp = s[n - 1]
					s[n - 1] = t[i]
					t[j] = tmp
					break
	print(len(op))
	for x in op:
		print(*x)
	k -= 1


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		s = list(rs())
		t = list(rs())
		d = Counter(s + t)
		f = 0
		for i in d:
			if d[i] % 2:
				print('No')
				f = 1
				break
		if f == 0:
			print('Yes')
			ans = []
			for i in range(n):
				if s[i] != t[i]:
					for j in range(i + 1, n):
						if s[i] == t[j]:
							(s[j], t[j]) = (t[j], s[j])
							ans.append([j + 1, j + 1])
							(s[j], t[i]) = (t[i], s[j])
							ans.append([j + 1, i + 1])
							break
						if s[i] == s[j]:
							(s[j], t[i]) = (t[i], s[j])
							ans.append([j + 1, i + 1])
							break
			print(len(ans))
			for i in ans:
				print(*i)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
input = sys.stdin.readline
k = int(input())
for i in range(k):
	n = int(input())
	freq = [0] * 28
	s = [i for i in input()]
	t = [i for i in input()]
	for i in range(n):
		freq[ord(s[i]) - 97] += 1
		freq[ord(t[i]) - 97] += 1
	ok = True
	for i in range(len(freq)):
		if freq[i] % 2 == 1:
			ok = False
	counter = 0
	swap = []
	for i in range(n):
		if s[i] != t[i]:
			for j in range(i + 1, n):
				if s[i] == s[j]:
					swap.append([j + 1, i + 1])
					(s[j], t[i]) = (t[i], s[j])
					counter += 1
					break
				elif s[i] == t[j]:
					swap.append([j + 1, j + 1])
					swap.append([j + 1, i + 1])
					counter += 2
					(s[j], t[j]) = (t[j], s[j])
					(s[j], t[i]) = (t[i], s[j])
					break
	if ok == False:
		print('No')
	else:
		print('Yes')
		print(counter)
		for i in range(len(swap)):
			print(*swap[i])


from collections import defaultdict
k = int(input())
for i in range(k):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	ans = []

	def swp(i, j):
		ans.append((i + 1, j + 1))
		(s1[i], s2[j]) = (s2[j], s1[i])
	c = defaultdict(int)
	for i in s1:
		c[i] += 1
	for i in s2:
		c[i] += 1
	for (k, v) in c.items():
		if v % 2 == 1:
			print('No')
			break
	else:
		print('Yes')
		for i in range(n):
			for j in range(i + 1, n):
				if s1[i] == s1[j]:
					swp(j, i)
					break
			else:
				for j in range(i + 1, n):
					if s1[i] == s2[j]:
						swp(i + 1, j)
						swp(i + 1, i)
						break
		if ans == []:
			ans.append([1, 1])
		assert s1 == s2
		assert len(ans) <= 2 * n
		print(len(ans))
		for i in ans:
			print(*i)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	s1 = list(input())
	sq = s + s1
	d = {}
	a = True
	for t in sq:
		if t not in d:
			d[t] = 0
		d[t] += 1
	for q in d:
		if d[q] % 2 == 1:
			print('No')
			a = False
			break
	if a:
		swaps = []
		for i in range(n):
			if s[i] == s1[i]:
				continue
			for j in range(i + 1, n):
				if s[i] == s[j]:
					swaps.append((j + 1, i + 1))
					(s1[i], s[j]) = (s[j], s1[i])
					break
				elif s[i] == s1[j]:
					swaps.append((j + 1, j + 1))
					(s[j], s1[j]) = (s1[j], s[j])
					swaps.append((j + 1, i + 1))
					(s1[i], s[j]) = (s[j], s1[i])
					break
		print('Yes')
		print(len(swaps))
		for x in swaps:
			print(*x)


k = int(input())
for i in range(k):
	n = int(input())
	s = list(input().strip())
	t = list(input().strip())
	l = []
	for j in range(n - 1):
		if s[j] == t[j]:
			pass
		else:
			flag = 0
			for a in range(j + 1, n):
				if s[a] == s[j]:
					flag = 1
					l.append([a, j])
					s[a] = t[j]
					t[j] = s[j]
					break
			if flag == 0:
				for a in range(j + 1, n):
					if t[a] == s[j]:
						flag = 1
						l.append([a, a])
						temp = s[a]
						s[a] = t[a]
						t[a] = temp
						l.append([a, j])
						s[a] = t[j]
						t[j] = s[j]
						break
				if flag == 0:
					break
	if s == t:
		print('Yes', end='\n')
		print(len(l), end='\n')
		for z in range(len(l)):
			print(l[z][0] + 1, l[z][1] + 1)
	else:
		print('No')


def valid(cnt):
	for i in cnt:
		if cnt[i] % 2 == 1:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	t = list(input())
	cnt = {}
	for i in s:
		if i not in cnt:
			cnt[i] = 1
		else:
			cnt[i] += 1
	for i in t:
		if i not in cnt:
			cnt[i] = 1
		else:
			cnt[i] += 1
	if not valid(cnt):
		print('No')
		continue
	res = []
	print('Yes')
	for i in range(n):
		if s[i] == t[i]:
			continue
		for j in range(i + 1, n):
			if s[j] == s[i]:
				(s[j], t[i]) = (t[i], s[j])
				res.append([j + 1, i + 1])
				break
			elif t[j] == s[i]:
				(s[i + 1], t[j]) = (t[j], s[i + 1])
				(s[i + 1], t[i]) = (t[i], s[i + 1])
				res.append([i + 2, j + 1])
				res.append([i + 2, i + 1])
				break
	print(len(res))
	for i in res:
		print(*i)


from sys import stdin, stdout
from collections import Counter

def upar(ind, ch):
	for i in range(ind, n):
		if s[i] == ch:
			return i
	return -1

def neeche(ind, ch):
	for i in range(ind, n):
		if s1[i] == ch:
			return i
	return -1
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = list(input())
	s1 = list(input())
	d = Counter(s)
	f = 1
	d1 = Counter(s1)
	for asc in range(97, 123):
		ch = chr(asc)
		if d.get(ch, 0) + d1.get(ch, 0) & 1:
			f = 0
			break
	if f == 0:
		print('No')
		continue
	l = []
	for i in range(n):
		if s[i] == s1[i]:
			continue
		p = upar(i + 1, s[i])
		if p != -1:
			l += [[p + 1, i + 1]]
			(s[p], s1[i]) = (s1[i], s[p])
			continue
		p = neeche(i + 1, s1[i])
		if p != -1:
			l += [[i + 1, p + 1]]
			(s[i], s1[p]) = (s1[p], s[i])
			continue
		l += [[i + 1, i + 1]]
		(s[i], s1[i]) = (s1[i], s[i])
		p = upar(i + 1, s[i])
		l += [[p + 1, i + 1]]
		(s[p], s1[i]) = (s1[i], s[p])
	print('Yes')
	print(len(l))
	for (k, v) in l:
		print(k, v)