You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'.

In one move, you can perform one of the following actions:

choose an occurrence of "ab" in $s$ and replace it with "ba";

choose an occurrence of "bc" in $s$ and replace it with "cb".

You are allowed to perform an arbitrary amount of moves (possibly, zero). Can you change string $s$ to make it equal to string $t$?


-----Input-----

The first line contains a single integer $q$ ($1 \le q \le 10^4$) — the number of testcases.

The first line of each testcase contains a single integer $n$ ($1 \le n \le 10^5$) — the length of strings $s$ and $t$.

The second line contains string $s$ of length $n$. Each character is 'a', 'b' or 'c'.

The third line contains string $t$ of length $n$. Each character is 'a', 'b' or 'c'.

The sum of $n$ over all testcases doesn't exceed $10^5$.


-----Output-----

For each testcase, print "YES" if you can change string $s$ to make it equal to string $t$ by performing an arbitrary amount of moves (possibly, zero). Otherwise, print "NO".


-----Examples-----

Input
5
3
cab
cab
1
a
b
6
abbabc
bbaacb
10
bcaabababc
cbbababaac
2
ba
ab
Output
YES
NO
YES
YES
NO


-----Note-----

None

Difficulty: MEDIUM

Solutions:
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	s = list(input().strip())
	t = input().strip()
	idx1 = start = 0
	while idx1 < n:
		(c1, c2) = (s[idx1], t[idx1])
		if c1 == c2:
			idx1 += 1
			continue
		if c1 == 'c':
			return 'NO'
		elif c1 == 'a':
			if c2 == 'c':
				return 'NO'
			j = max(start, idx1 + 1)
			while j < n and s[j] != 'b':
				if s[j] == 'c':
					return 'NO'
				j += 1
			if j == n:
				return 'NO'
			(s[idx1], s[j]) = (s[j], s[idx1])
			start = j + 1
		else:
			if c2 == 'a':
				return 'NO'
			j = max(start, idx1 + 1)
			while j < n and s[j] != 'c':
				if s[j] == 'a':
					return 'NO'
				j += 1
			if j == n:
				return 'NO'
			(s[idx1], s[j]) = (s[j], s[idx1])
			start = j + 1
		idx1 += 1
	if s[-1] != t[-1]:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(solve())


import sys
from itertools import accumulate
sys.setrecursionlimit(2 * 10 ** 6)

def test():
	pass

def solve(n, s, t):
	sl = list(s)
	j = -1
	for i in range(n):
		if sl[i] == t[i]:
			continue
		if sl[i] == 'a' and t[i] == 'b':
			if j < i:
				j = i
			while j < n and sl[j] == 'a':
				j += 1
			if j < n and sl[j] == 'b':
				sl[j] = 'a'
				continue
			else:
				return 'NO'
		if sl[i] == 'b' and t[i] == 'c':
			if j < i:
				j = i
			while j < n and sl[j] == 'b':
				j += 1
			if j < n and sl[j] == 'c':
				sl[j] = 'b'
				continue
			else:
				return 'NO'
		return 'NO'
	return 'YES'

def main():
	N = int(input())
	for _ in range(N):
		n = int(input())
		s = input()
		t = input()
		print(solve(n, s, t))

def init():
	import sys
	import os
	if 'DOCKER_HOST' in os.environ:
		test()
		sys.stdin = open('test.txt')
init()
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	if s.count('b') != t.count('b'):
		print('NO')
		continue
	j = 0
	for i in range(n):
		if s[i] == 'b':
			continue
		while t[j] == 'b':
			j += 1
		if s[i] != t[j] or (s[i] == 'a' and i > j) or (s[i] == 'c' and i < j):
			print('NO')
			break
		j += 1
	else:
		print('YES')


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

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

def test_ok(ok):
	print('YES' if ok else 'NO')

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		t = input()
		if s.count('b') != t.count('b'):
			print('NO')
			continue
		j = 0
		for i in range(n):
			if s[i] == 'b':
				continue
			while t[j] == 'b':
				j += 1
			if s[i] != t[j] or (s[i] == 'a' and i > j) or (s[i] == 'c' and i < j):
				print('NO')
				break
			j += 1
		else:
			print('YES')
main()


q = int(input())
for _ in range(q):
	n = int(input())
	s = input().strip()
	t = input().strip()
	stack_s = 0
	stack_t = 0
	for (s_c, t_c) in zip(s, t):
		if s_c == 'a':
			if stack_t == 0:
				stack_s += 1
			else:
				break
		if t_c == 'a':
			if stack_s > 0 and stack_t == 0:
				stack_s -= 1
			else:
				break
		if t_c == 'c':
			if stack_s == 0:
				stack_t += 1
			else:
				break
		if s_c == 'c':
			if stack_s == 0 and stack_t > 0:
				stack_t -= 1
			else:
				break
	else:
		if stack_s == stack_t == 0:
			print('YES')
			continue
	print('NO')


strng = lambda : input()
inp = lambda : int(input())
mul = lambda : map(int, input().split())
jn = lambda x, l: x.join(map(str, l))
strlst = lambda : list(input())
lst = lambda : list(map(int, input().split()))
dd = lambda : defaultdict(lambda : 0)
import sys
input = sys.stdin.readline
from collections import defaultdict, Counter
from math import ceil, log, floor, sqrt, gcd, log10
for _ in range(inp()):
	n = inp()
	a = strlst()
	b = strlst()
	posb = 0
	posc = 0
	for i in range(n):
		if b[i] == a[i]:
			continue
		if b[i] == 'a':
			break
		if b[i] == 'b':
			for j in range(max(posb, i), n):
				if a[j] != 'a':
					break
			posb = j
		elif b[i] == 'c':
			for j in range(max(posc, i), n):
				if a[j] != 'b':
					break
			posc = j
		else:
			break
		if b[i] != a[j]:
			break
		(a[i], a[j]) = (a[j], a[i])
	else:
		print('YES')
		continue
	print('NO')


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	if not s1.count('b') == s2.count('b'):
		print('NO')
		continue
	else:
		j = 0
		for i in range(n):
			if s1[i] == 'b':
				continue
			while s2[j] == 'b':
				j += 1
			if s1[i] != s2[j] or (s1[i] == 'a' and i > j) or (s1[i] == 'c' and j > i):
				print('NO')
				break
			j += 1
		else:
			print('YES')


(I, P, N) = (input, print, 'NO')
for i in range(int(I())):
	n = int(I())
	s = I()
	t = I()
	if s.count('b') != t.count('b'):
		P(N)
		continue
	(j, z) = (0, 'YES')
	for i in range(n):
		x = s[i]
		if x == 'b':
			continue
		while t[j] == 'b':
			j += 1
		y = t[j]
		if x != y or (x == 'a' and i > j) or (x == 'c' and i < j):
			z = N
			break
		j += 1
	P(z)


def solve():
	n = int(input())
	p = input()
	q = input()
	(i, j) = (0, 0)
	while i < n or j < n:
		while i < n and p[i] == 'b':
			i += 1
		while j < n and q[j] == 'b':
			j += 1
		if i == n and j == n:
			break
		if i < n and j == n or (j < n and i == n):
			print('NO')
			return
		if p[i] != q[j] or (p[i] == 'a' and j < i) or (p[i] == 'c' and j > i):
			print('NO')
			return
		i += 1
		j += 1
	print('YES')
t = int(input())
for _ in range(t):
	solve()


x = int(input())

def cal(n, s, t):
	if s == t:
		return True
	(p, q) = (list(s), list(t))
	i = n - 1
	(a, b) = (n - 1, n - 1)
	while i >= 0:
		if q[i] == p[i]:
			i -= 1
			continue
		if q[i] == 'c':
			return False
		if q[i] == 'b':
			ck = 0
			for j in range(min(i, b), -1, -1):
				if p[j] == 'a':
					return False
				elif p[j] == 'b':
					b = j
					(p[j], p[i]) = (p[i], p[j])
					ck = 1
					break
			if ck == 0:
				return False
		else:
			ck = 0
			for j in range(min(i, a), -1, -1):
				if p[j] == 'c':
					return False
				elif p[j] == 'a':
					a = j
					(p[j], p[i]) = (p[i], p[j])
					ck = 1
					break
			if ck == 0:
				return False
		i -= 1
	return True
for jj in range(x):
	n = int(input())
	(s, t) = (input(), input())
	if cal(n, s, t):
		print('YES')
	else:
		print('NO')


import itertools
for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	ls = []
	lt = []
	at_count = 0
	ct_count = 0
	as_count = 0
	cs_count = 0
	flag = False
	for (chars, chart) in zip(s, t):
		if chars == 'a':
			ls.append(0)
			as_count += 1
		elif chars == 'c':
			ls.append(1)
			cs_count += 1
		if chart == 'a':
			lt.append(0)
			at_count += 1
		elif chart == 'c':
			lt.append(1)
			ct_count += 1
		if at_count > as_count or cs_count > ct_count:
			flag = True
	if not flag:
		if ls == lt:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def solve(arr_a, arr_b):
	(a, b, c) = (0, 0, 0)
	(ba, bb) = ([], [])
	(ca, cb) = ([], [])
	(cba, cbb) = ([], [])
	for i in arr_a:
		if i == 'a':
			a += 1
			ba.append(b)
			ca.append(c)
		if i == 'b':
			b += 1
			cba.append(c)
		if i == 'c':
			c += 1
	(a2, b2, c2) = (0, 0, 0)
	for i in arr_b:
		if i == 'a':
			a2 += 1
			bb.append(b2)
			cb.append(c2)
		if i == 'b':
			b2 += 1
			cbb.append(c2)
		if i == 'c':
			c2 += 1
	if a != a2 or b != b2 or c != c2:
		return False
	for i in range(len(ba)):
		if ba[i] > bb[i] or ca[i] != cb[i]:
			return False
	for i in range(len(cba)):
		if cba[i] > cbb[i]:
			return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	arr_a = input()
	arr_b = input()
	if solve(arr_a, arr_b):
		print('YES')
	else:
		print('NO')


def solve():
	n = int(input())
	s = input()
	t = input()
	s1 = []
	t1 = []
	ss1 = []
	tt1 = []
	for i in range(n):
		if s[i] == 'a' or s[i] == 'c':
			s1.append(s[i])
			ss1.append(i)
		if t[i] == 'a' or t[i] == 'c':
			t1.append(t[i])
			tt1.append(i)
	if len(s1) != len(t1):
		print('NO')
		return
	for i in range(len(s1)):
		if s1[i] != t1[i]:
			print('NO')
			return
		if s1[i] == 'a' and ss1[i] > tt1[i]:
			print('NO')
			return
		if s1[i] == 'c' and ss1[i] < tt1[i]:
			print('NO')
			return
	print('YES')
q = int(input())
while q:
	solve()
	q -= 1


q = int(input())
while q:
	n = int(input())
	s = input()
	t = input()
	flag = 1
	if s.count('a') != t.count('a') or s.count('b') != t.count('b') or s.count('c') != t.count('c'):
		flag = 0
	else:
		i = 0
		j = 0
		while i < n:
			if s[i] == 'b':
				i += 1
				continue
			while t[j] == 'b':
				j += 1
			if s[i] != t[j] or (s[i] == 'a' and i > j) or (s[i] == 'c' and i < j):
				flag = 0
				break
			i += 1
			j += 1
	if flag:
		print('YES')
	else:
		print('NO')
	q -= 1


g = int(input())

def logic(n, s, t):
	s2 = [c for c in s if c != 'b']
	t2 = [c for c in t if c != 'b']
	if s2 != t2:
		return 'NO'
	s_a = []
	s_c = []
	t_a = []
	t_c = []
	for i in range(n):
		if s[i] == 'a':
			s_a.append(i)
		elif s[i] == 'c':
			s_c.append(i)
		if t[i] == 'a':
			t_a.append(i)
		elif t[i] == 'c':
			t_c.append(i)
	for i in range(len(s_a)):
		if s_a[i] > t_a[i]:
			return 'NO'
	for i in range(len(s_c)):
		if s_c[i] < t_c[i]:
			return 'NO'
	return 'YES'
for a in range(g):
	n = int(input())
	s = input()
	t = input()
	print(logic(n, s, t))


def pp(s: str, t: str, n: int) -> str:
	if s.count('a') != t.count('a') or s.count('b') != t.count('b') or s.count('c') != t.count('c'):
		return 'NO'
	(p1, p2) = (0, 0)
	while p1 < n and p2 < n:
		while p1 < n and s[p1] == 'b':
			p1 += 1
		if p1 == n:
			break
		while p2 < n and t[p2] == 'b':
			p2 += 1
		if s[p1] != t[p2]:
			return 'NO'
		if s[p1] == 'a':
			if p1 > p2:
				return 'NO'
		elif p1 < p2:
			return 'NO'
		p1 += 1
		p2 += 1
	return 'YES'
n = int(input())
for i in range(n):
	tt = int(input())
	(s, t) = (input(), input())
	print(pp(s, t, tt))


def solve():
	n = int(input())
	(s, t) = (input(), input())
	(A, B) = ('', '')
	(aa, ac, ba, bc) = (0, 0, 0, 0)
	for i in range(n):
		if s[i] == 'a':
			aa += 1
		if s[i] == 'c':
			ac += 1
		if t[i] == 'a':
			ba += 1
		if t[i] == 'c':
			bc += 1
		if ba > aa or bc < ac:
			print('NO')
			return
		if s[i] != 'b':
			A += s[i]
		if t[i] != 'b':
			B += t[i]
	print(('YES', 'NO')[A != B])
for T in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	s1 = sorted(s)
	t1 = sorted(t)
	if s1 != t1:
		print('NO')
	elif s == t:
		print('YES')
	else:
		a = 0
		c = 0
		flag = True
		for x in range(n):
			if s[x] == t[x] and s[x] == 'b':
				continue
			else:
				if a != 0 and t[x] == 'c' or (c != 0 and s[x] == 'a'):
					flag = False
					break
				if s[x] == 'a' and t[x] == 'b':
					a += 1
				elif s[x] == 'b' and t[x] == 'c':
					c += 1
				elif s[x] == 'b' and t[x] == 'a':
					a -= 1
					if a < 0:
						flag = False
						break
				elif s[x] == 'c' and t[x] == 'b':
					c -= 1
					if c < 0:
						flag = False
						break
				elif s[x] == 'a' and t[x] == 'c' or (s[x] == 'c' and t[x] == 'a'):
					flag = False
					break
		if flag:
			print('YES')
		else:
			print('NO')


T = int(input())
while T > 0:
	n = int(input())
	s = input()
	t = input()
	ptr1 = ptr2 = 0
	ans = True
	while True:
		while ptr1 < n and s[ptr1] == 'b':
			ptr1 += 1
		while ptr2 < n and t[ptr2] == 'b':
			ptr2 += 1
		if ptr1 == n and ptr2 == n:
			break
		if ptr1 == n or ptr2 == n or s[ptr1] != t[ptr2]:
			ans = False
			break
		if s[ptr1] == 'a' and ptr1 > ptr2 or (s[ptr1] == 'c' and ptr1 < ptr2):
			ans = False
			break
		ptr1 += 1
		ptr2 += 1
	if ptr1 != n or ptr2 != n:
		ans = False
	if ans:
		print('YES')
	else:
		print('NO')
	T -= 1


iter = int(input())
for z in range(iter):
	n = int(input())
	a = input()
	b = input()
	top = 0
	ans = 1
	for i in range(n):
		if b[i] == 'a':
			top -= 1
		if a[i] == 'a':
			top += 1
		if top < 0:
			ans = 0
			break
		if top and a[i] == 'c':
			ans = 0
			break
	if top > 0:
		ans = 0
	if ans:
		top = 0
		for i in range(n - 1, -1, -1):
			if b[i] == 'c':
				top -= 1
			if a[i] == 'c':
				top += 1
			if top < 0:
				ans = 0
				break
			if top and b[i] == 'a':
				ans = 0
				break
		if top > 0:
			ans = 0
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	sa = input()
	sb = input()
	lsta = []
	lstb = []
	for j in range(n):
		if sa[j] != 'b':
			lsta.append((sa[j], j))
		if sb[j] != 'b':
			lstb.append((sb[j], j))
	e = 0
	if len(lsta) != len(lstb):
		print('NO')
	else:
		l = len(lsta)
		for j in range(l):
			if lsta[j][0] == 'a':
				if lstb[j][0] == 'a':
					if lstb[j][1] < lsta[j][1]:
						e += 1
						break
				else:
					e += 1
					break
			elif lsta[j][0] == 'c':
				if lsta[j][0] == 'c':
					if lstb[j][0] == 'c':
						if lstb[j][1] > lsta[j][1]:
							e += 1
							break
					else:
						e += 1
						break
			else:
				e += 1
				break
		if e == 0:
			print('YES')
		else:
			print('NO')


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
INF = float('inf')
mod = 1000000007

def solve():
	n = int(input())
	s = input()
	d = input()
	(ok_s, ok_d) = ('', '')
	for i in range(n):
		if s[i] != 'b':
			ok_s += s[i]
		if d[i] != 'b':
			ok_d += d[i]
	if ok_s != ok_d:
		print('NO')
		return
	(net_s, net_d) = ([], [])
	for i in range(n):
		if s[i] == 'a':
			net_s.append(i)
		if d[i] == 'a':
			net_d.append(i)
	for i in range(len(net_s)):
		if net_d[i] >= net_s[i]:
			continue
		else:
			print('NO')
			return
	(net_s, net_d) = ([], [])
	for i in range(n):
		if s[i] == 'c':
			net_s.append(i)
		if d[i] == 'c':
			net_d.append(i)
	for i in range(len(net_s)):
		if net_d[i] <= net_s[i]:
			continue
		else:
			print('NO')
			return
	print('YES')
t = int(input())
while t != 0:
	solve()
	t -= 1


class Solution:

	def solve(self, n, s, t):
		si_list = []
		ti_list = []
		for i in range(n):
			if s[i] != 'b':
				si_list.append(s[i])
			if t[i] != 'b':
				ti_list.append(t[i])
		if si_list != ti_list:
			return False
		csi_index = []
		cti_index = []
		asi_index = []
		ati_index = []
		for i in range(n):
			if s[i] == 'c':
				csi_index.append(i)
			elif s[i] == 'a':
				asi_index.append(i)
			if t[i] == 'c':
				cti_index.append(i)
			elif t[i] == 'a':
				ati_index.append(i)
		for i in range(len(csi_index)):
			if csi_index[i] < cti_index[i]:
				return False
		for i in range(len(asi_index)):
			if ati_index[i] < asi_index[i]:
				return False
		return True
sol = Solution()
c = int(input())
while c > 0:
	n = int(input())
	s = input()
	t = input()
	flag = sol.solve(n, s, t)
	if flag == True:
		print('YES')
	else:
		print('NO')
	c -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	numA = 0
	numC = 0
	ans = s.replace('b', '') == t.replace('b', '')
	for i in range(n):
		numA += (s[i] == 'a') - (t[i] == 'a')
		numC += (t[i] == 'c') - (s[i] == 'c')
		if numA < 0 or numC < 0:
			ans = False
	print('YES' if ans else 'NO')


import abc
import itertools
import math
from math import gcd as gcd
import sys
import queue
import itertools
from heapq import heappop, heappush
import random

def solve():
	n = int(sys.stdin.readline())
	s = str(sys.stdin.readline())
	t = str(sys.stdin.readline())
	counter = {'a': 0, 'b': 0, 'c': 0}
	ca_s = ''
	ca_t = ''
	for i in range(n):
		counter[s[i]] += 1
		counter[t[i]] -= 1
		if s[i] != 'b':
			ca_s += s[i]
		if t[i] != 'b':
			ca_t += t[i]
		if max(len(ca_t), len(ca_s)) > 0:
			if len(ca_t) == len(ca_s):
				if ca_t[-1] != ca_s[-1]:
					print('NO')
					return
			elif len(ca_t) > len(ca_s):
				if ca_t[-1] == 'a':
					print('NO')
					return
			elif ca_s[-1] == 'c':
				print('NO')
				return
	if [min(counter.values()), max(counter.values())] != [0, 0] or ca_s != ca_t:
		print('NO')
		return
	print('YES')
multi_test = 1
if multi_test == 1:
	t = int(sys.stdin.readline())
	for _ in range(t):
		solve()
else:
	solve()


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	sac = []
	(sa, sc, ta, tc) = (0, 0, 0, 0)
	tac = []
	ans = 'YES'
	for i in range(n):
		if s[i] != 'b':
			sac.append(s[i])
		if t[i] != 'b':
			tac.append(t[i])
		if s[i] == 'a':
			sa += 1
		if s[i] == 'c':
			sc += 1
		if t[i] == 'a':
			ta += 1
		if t[i] == 'c':
			tc += 1
		if ta > sa or sc > tc:
			ans = 'NO'
			break
	if sac == tac and sa == ta and (ans == 'YES'):
		print(ans)
	else:
		print('NO')


TT = int(input())
while TT:
	n = int(input())
	s1 = input()
	s2 = input()
	SCA1 = []
	SCA2 = []
	for i in range(n):
		if s1[i] != 'b':
			SCA1.append([s1[i], i])
		if s2[i] != 'b':
			SCA2.append([s2[i], i])
	flag = 1
	if len(SCA1) != len(SCA2):
		flag = 0
	else:
		for i in range(len(SCA1)):
			if SCA1[i][0] != SCA2[i][0]:
				flag = 0
				break
			elif SCA1[i][0] == 'a':
				if SCA1[i][1] > SCA2[i][1]:
					flag = 0
					break
			elif SCA1[i][1] < SCA2[i][1]:
				flag = 0
				break
	if flag:
		print('YES')
	else:
		print('NO')
	TT -= 1


import collections
import math
import sys
from queue import PriorityQueue
from random import randint

def main(testnumber):
	n = int(input())
	s = input()
	s1 = input()
	ss = []
	ss1 = []
	for i in range(n):
		if s[i] != 'b':
			ss.append(s[i])
		if s1[i] != 'b':
			ss1.append(s1[i])
	if ''.join(ss) == ''.join(ss1):
		cs = 0
		cs1 = 0
		no = False
		for i in range(n):
			if s[i] == 'c':
				cs += 1
			elif s[i] == 'a':
				cs = 0
			if s1[i] == 'c':
				cs1 += 1
			elif s1[i] == 'a':
				cs1 = 0
			if cs1 < cs:
				no = True
				break
		ac = 0
		ac1 = 0
		for i in range(n):
			if s[i] == 'a':
				ac += 1
			elif s[i] == 'c':
				ac = 0
			if s1[i] == 'a':
				ac1 += 1
			elif s1[i] == 'c':
				ac1 = 0
			if ac1 > ac:
				no = True
				break
		if no:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
t = int(input())
cnt = 1
while t > 0:
	main(cnt)
	cnt += 1
	t -= 1


def oper(l, m):
	(q, r) = (0, 0)
	for i in range(len(l)):
		if m[i] == 'c':
			q = max(i, q)
			while q < len(l):
				if l[q] == 'c':
					(l[i], l[q]) = (l[q], l[i])
					q += 1
					break
				elif l[q] == 'a':
					return 'NO'
				q += 1
		if m[i] == 'b':
			r = max(i, r)
			while r < len(l):
				if l[r] == 'b':
					(l[i], l[r]) = (l[r], l[i])
					r += 1
					break
				elif l[r] == 'c':
					return 'NO'
				r += 1
	if l == m:
		return 'YES'
	return 'NO'
t = int(input())
for vmlskv in range(t):
	n = int(input())
	a = input()
	b = input()
	l = []
	m = []
	for i in range(n):
		l.append(a[i])
		m.append(b[i])
	print(oper(l, m))


x = int(input())
while x > 0:
	x -= 1
	n = int(input())
	s = str(input())
	t = str(input())
	s = list(s)
	t = list(t)
	(y, u) = (0, 0)
	ans = 'YES'
	if s.count('a') != t.count('a') or s.count('b') != t.count('b') or s.count('c') != t.count('c'):
		print('NO')
		continue
	for i in range(0, n):
		if s[i] == t[i]:
			continue
		elif s[i] == 'a':
			if i == n - 1 or t[i] != 'b':
				ans = 'NO'
				break
			else:
				j = max(y, i + 1)
				while j < n and s[j] == 'a':
					j += 1
				y = j
				if j == n or s[j] != 'b':
					ans = 'NO'
					break
				(s[i], s[j]) = (s[j], s[i])
		elif s[i] == 'b':
			if i == n - 1 or t[i] != 'c':
				ans = 'NO'
				break
			else:
				j = max(u, i + 1)
				while j < n and s[j] == 'b':
					j += 1
				u = j
				if j == n or s[j] != 'c':
					ans = 'NO'
					break
				(s[i], s[j]) = (s[j], s[i])
		else:
			ans = 'NO'
			break
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	(s, t) = (input(), input())
	if s.count('a') != t.count('a') or s.count('b') != t.count('b') or s.count('c') != t.count('c'):
		print('NO')
		continue
	myDict1 = defaultdict(list)
	myDict2 = defaultdict(list)
	for i in range(n):
		myDict1[s[i]].append(i)
		myDict2[t[i]].append(i)
	if s.count('a') > 0:
		flag = True
		for i in range(s.count('a')):
			if myDict2['a'][i] < myDict1['a'][i]:
				flag = False
				break
		if not flag:
			print('NO')
			continue
	if s.count('c') > 0:
		flag = True
		for i in range(s.count('c')):
			if myDict2['c'][i] > myDict1['c'][i]:
				flag = False
				break
		if not flag:
			print('NO')
			continue
	s = ''.join(s.split('b'))
	t = ''.join(t.split('b'))
	if s != t:
		print('NO')
	else:
		print('YES')


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

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())
for T in range(int(input())):
	n = ni()
	s = list(si())
	t = list(si())
	flag = True
	i = 0
	a1 = 0
	a2 = 0
	c1 = 0
	c2 = 0
	flag = True
	d1 = ''
	d2 = ''
	for i in s:
		if i != 'b':
			d1 += i
	for i in t:
		if i != 'b':
			d2 += i
	if d1 != d2:
		flag = False
	for i in range(n):
		if c1 > c2:
			flag = False
			break
		if s[i] == 'c':
			c1 += 1
		if t[i] == 'c':
			c2 += 1
	s.reverse()
	t.reverse()
	for i in range(n):
		if a1 > a2:
			flag = False
			break
		if s[i] == 'a':
			a1 += 1
		if t[i] == 'a':
			a2 += 1
	if flag:
		print('YES')
	else:
		print('NO')


def check(s):
	coun = [0, 0, 0]
	for i in s:
		coun[ord(i) - ord('a')] += 1
	return coun
q = int(input())
for test in range(q):
	n = int(input())
	s = list(input())
	t = list(input())
	flag = 0
	b = 0
	c = 0
	if check(s) != check(t):
		flag = 1
		print('NO')
	else:
		i = 0
		while i < n:
			if s[i] == t[i]:
				i += 1
				continue
			else:
				if i == n - 1:
					flag = 1
					print('NO')
					break
				elif s[i] == 'a' and t[i] == 'b':
					start = max(i, b)
					while start < n and s[start] == 'a':
						start += 1
					if start == n or s[start] == 'c':
						flag = 1
						print('NO')
						break
					s[start] = 'a'
					b = start + 1
				elif s[i] == 'b' and t[i] == 'c':
					start = max(i, c)
					while start < n and s[start] == 'b':
						start += 1
					if start == n or s[start] == 'a':
						flag = 1
						print('NO')
						break
					s[start] = 'b'
					c = start + 1
				else:
					flag = 1
					print('NO')
					break
				i += 1
	if flag == 0:
		print('YES')


Z = int(input())
while Z != 0:
	N = int(input())
	S = str(input())
	T = str(input())
	result = True
	test1 = ''
	test2 = ''
	for i in range(len(S)):
		if S[i] != 'b':
			test1 += S[i]
		if T[i] != 'b':
			test2 += T[i]
	count_c_S = 0
	count_c_T = 0
	for i in range(len(S)):
		if count_c_S > count_c_T:
			result = False
			break
		if S[i] == 'c':
			count_c_S += 1
		if T[i] == 'c':
			count_c_T += 1
	S = S[::-1]
	T = T[::-1]
	count_a_S = 0
	count_a_T = 0
	for i in range(len(S)):
		if count_a_S > count_a_T:
			result = False
			break
		if S[i] == 'a':
			count_a_S += 1
		if T[i] == 'a':
			count_a_T += 1
	if result == True and test2 == test1:
		print('YES')
	else:
		print('NO')
	Z -= 1


from collections import defaultdict
q = int(input())
for x in range(q):
	n = int(input())
	s = input()
	t = input()
	ans = 'YES'
	if s.replace('b', '') != t.replace('b', ''):
		ans = 'NO'
	else:
		d = defaultdict(list)
		e = defaultdict(list)
		for (i, c) in enumerate(s):
			d[c].append(i)
		for (i, c) in enumerate(t):
			e[c].append(i)
		for i in range(len(d['a'])):
			if d['a'][i] > e['a'][i]:
				ans = 'NO'
				break
		for i in range(len(d['c'])):
			if d['c'][i] < e['c'][i]:
				ans = 'NO'
				break
	print(ans)


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input().strip('\n'))
	(s, t) = (input().strip('\n'), input().strip('\n'))
	s = list(s)
	(ap, bp, cp) = (0, 0, 0)
	for j in range(n):
		ap = max(ap, j + 1)
		while ap < n and s[ap] != 'a':
			ap += 1
		bp = max(bp, j + 1)
		while bp < n and s[bp] != 'b':
			bp += 1
		cp = max(cp, j + 1)
		while cp < n and s[cp] != 'c':
			cp += 1
		if s[j] != t[j]:
			if s[j] == 'a':
				if t[j] == 'b':
					if bp == n or cp < bp:
						print('NO')
						break
					else:
						(s[bp], s[j]) = (s[j], s[bp])
						bp += 1
						while bp < n and s[bp] != 'b':
							bp += 1
				else:
					print('NO')
					break
			elif s[j] == 'b':
				if t[j] == 'c':
					if cp == n or ap < cp:
						print('NO')
						break
					else:
						(s[cp], s[j]) = (s[j], s[cp])
						cp += 1
						while cp < n and s[cp] != 'c':
							cp += 1
				else:
					print('NO')
					break
			else:
				print('NO')
				break
	else:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	answ = ['YES', 'NO']
	if Counter(s) != Counter(t):
		print('NO')
		continue
	j = 0
	for (i, ch) in enumerate(s):
		if s[i] == 'b':
			continue
		while t[j] == 'b':
			j += 1
		if s[i] != t[j] or (s[i] == 'a' and i > j) or (s[i] == 'c' and i < j):
			answ.pop(0)
			break
		j += 1
	print(answ[0])


a = int(input())
for y in range(a):
	b = int(input())
	c = input()
	d = input()
	if c.count('b') == d.count('b') and c.count('a') == d.count('a') and (c.count('c') == d.count('c')):
		j = []
		h = []
		i = []
		k = []
		f = 0
		for y in range(b):
			if c[y] == 'a' or c[y] == 'c':
				j.append([c[y], y])
				i.append(c[y])
			if d[y] == 'a' or d[y] == 'c':
				h.append([d[y], y])
				k.append(d[y])
		if i != k:
			print('NO')
		else:
			s = len(j)
			for y in range(s):
				if j[y][0] == 'a':
					if j[y][1] > h[y][1]:
						f = -1
						break
				elif j[y][1] < h[y][1]:
					f = -1
					break
			if f == -1:
				print('NO')
			else:
				print('YES')
	else:
		print('NO')


import collections
q = int(input())
for _ in range(q):
	n = int(input())
	s = list(input())
	t = list(input())
	occ_s = collections.defaultdict(int)
	occ_t = collections.defaultdict(int)
	s2 = ''
	t2 = ''
	for i in range(n):
		occ_s[s[i]] += 1
		occ_t[t[i]] += 1
		if s[i] != 'b':
			s2 += s[i]
		if t[i] != 'b':
			t2 += t[i]
	if s2 != t2:
		print('NO')
		continue
	(l, r) = (0, 0)
	i = 0
	flag = True
	while i < occ_s['a']:
		while s[l] != 'a':
			l += 1
		while t[r] != 'a':
			r += 1
		i += 1
		l += 1
		r += 1
		if l > r:
			flag = False
			break
	if not flag:
		print('NO')
		continue
	(l, r) = (0, 0)
	i = 0
	while i < occ_s['c']:
		while s[l] != 'c':
			l += 1
		while t[r] != 'c':
			r += 1
		i += 1
		l += 1
		r += 1
		if r > l:
			flag = False
			break
	print('NO') if not flag else print('YES')


import sys, collections
for _ in range(int(input())):
	n = int(input())
	s = str(input())
	t = str(input())
	astack = []
	cstack = []
	ct = [[0, 0, 0], [0, 0, 0]]
	for i in range(n):
		if s[i] == 'a':
			ct[0][0] += 1
		elif s[i] == 'b':
			ct[0][1] += 1
		else:
			ct[0][2] += 1
	for i in range(n):
		if t[i] == 'a':
			ct[1][0] += 1
		elif t[i] == 'b':
			ct[1][1] += 1
		else:
			ct[1][2] += 1
	if ct[0] != ct[1]:
		print('NO')
	else:
		for i in range(n):
			if s[i] == 'a':
				astack.append('a')
			elif s[i] == 'c':
				if len(astack):
					print('NO')
					break
			if t[i] == 'a':
				if len(astack):
					astack.pop()
				else:
					print('NO')
					break
		else:
			for i in range(n - 1, -1, -1):
				if s[i] == 'c':
					cstack.append('c')
				elif s[i] == 'a' or t[i] == 'a':
					if len(cstack):
						print('NO')
						break
				if t[i] == 'c':
					if len(cstack):
						cstack.pop()
					else:
						print('NO')
						break
			else:
				print('YES')


import sys

def do_count(s, char):
	counter = 0
	arr = []
	for c in s:
		if c == char:
			arr.append(counter)
			counter = 0
		else:
			counter += 1
	arr.append(counter)
	return arr
for _ in range(int(input())):
	input()
	s = input()
	t = input()
	valid = True
	for c in 'abc':
		if s.count(c) != t.count(c):
			valid = False
	if not valid:
		print('NO')
		continue
	if ''.join((c for c in s if c != 'b')) != ''.join((c for c in t if c != 'b')):
		print('NO')
		continue
	arrsa = do_count(s, 'a')
	arrta = do_count(t, 'a')
	arrsc = do_count(s, 'c')
	arrtc = do_count(t, 'c')
	print(arrsa, arrta, file=sys.stderr)
	print(arrsc, arrtc, file=sys.stderr)
	sums = 0
	sumt = 0
	for i in range(len(arrsa)):
		sums += arrsa[i]
		sumt += arrta[i]
		if sums > sumt:
			valid = False
	sums = 0
	sumt = 0
	for i in range(len(arrtc)):
		sums += arrsc[i]
		sumt += arrtc[i]
		if sums < sumt:
			valid = False
	if not valid:
		print('NO')
	else:
		print('YES')


from collections import deque, defaultdict
q = int(input())
for _ in range(q):
	n = int(input())
	s = input()
	t = input()
	d = defaultdict(deque)
	ok = True
	for i in range(n):
		d[s[i]].append(i)
	for c in 'abc':
		d[c].append(n)
	for i in range(n):
		tc = t[i]
		ind = min(list(map(lambda x: x[0], d.values())))
		sc = s[ind]
		if sc == tc:
			d[sc].popleft()
		elif sc == 'a' and tc == 'b' or (sc == 'b' and tc == 'c'):
			other = 'c' if sc == 'a' else 'a'
			if d[other][0] > d[tc][0]:
				d[tc].popleft()
			else:
				ok = 0
				break
		else:
			ok = 0
			break
	print('YES' if ok else 'NO')


import re
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = [0, 0]
	f = 1
	for (i, j) in zip(list(re.sub('c', '', a)), list(re.sub('c', '', b))):
		c[0] += int(i == 'b')
		c[1] += int(j == 'b')
		f = min(f, c[0] <= c[1])
	for (i, j) in zip(list(re.sub('a', '', a)), list(re.sub('a', '', b))):
		c[0] += int(i == 'b')
		c[1] += int(j == 'b')
		f = min(f, c[0] >= c[1])
	x = '|'.join(re.sub('b', '', a).split('a')) + '|'.join(re.sub('b', '', a).split('c'))
	y = '|'.join(re.sub('b', '', b).split('a')) + '|'.join(re.sub('b', '', b).split('c'))
	print(['NO', 'YES'][x == y and f])


q = int(input())
for _ in range(q):
	n = int(input())
	s = input()
	t = input()
	ans = 'YES'
	cur = 0
	for i in range(n - 1):
		if s[i] == t[i]:
			continue
		if t[i] == 'a':
			ans = 'NO'
			break
		elif t[i] == 'b':
			try:
				ind = s.index('b', i + 1)
			except ValueError:
				ans = 'NO'
				break
			if s[i:ind] == 'a' * (ind - i):
				s = s[:i] + 'b' + 'a' * (ind - i) + s[ind + 1:]
			else:
				ans = 'NO'
				break
		else:
			try:
				ind = s.index('c', i + 1)
			except ValueError:
				ans = 'NO'
				break
			if s[i:ind] == 'b' * (ind - i):
				s = s[:i] + 'c' + 'b' * (ind - i) + s[ind + 1:]
			else:
				ans = 'NO'
				break
	if s[n - 1] != t[n - 1]:
		ans = 'NO'
	print(ans)