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$$$?

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$$$.

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".

5

3

cab

cab

1

a

b

6

abbabc

bbaacb

10

bcaabababc

cbbababaac

2

ba

ab

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strings"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

var n,m int
var turn int
var s,t string
func solve(){
	var l int
	Fscan(r,&l)
	Fscan(r,&s,&t)
	if strings.ReplaceAll(s,"b","") !=strings.ReplaceAll(t,"b",""){
		Fprintln(w,"NO")
		return
	}
	// 'a' means move_right
	// 'c' means move_left
	ptr_1,ptr_2:=0,0
	for ptr_1<l{
		if s[ptr_1]=='b'{
			ptr_1++
			continue
		}
		if t[ptr_2]=='b'{
			ptr_2++
			continue
		}
		if s[ptr_1]=='a' && ptr_1>ptr_2{
			Fprintln(w,"NO")
			return
		}
		if s[ptr_1]=='c' && ptr_1<ptr_2{
			Fprintln(w,"NO")
			return
		}
		ptr_1++
		ptr_2++
	}
	Fprintln(w,"YES")
	return
}

func main(){
	defer w.Flush()
	//Fscan(r,&n,&m)
	Fscan(r,&turn)

	for i:=0;i<turn;i++{
	    solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====

acabcca
1020003

*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
		}
		if i != 0 {
			aCnt[i] += aCnt[i-1]
		}

		if s[i] == 'c' {
			cCnt[i]++
		}
		if i != 0 {
			cCnt[i] += cCnt[i-1]
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if s[i] == 'a' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[i] - cCnt[j]
			if s[j] == 'c' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ca, cc int
		for i := range s1 {
			if s1[i] == 'a' {
				ca++
			} else if (s1[i] == 'c' || s2[i] == 'c') && ca != 0 {
				f = false
				break
			}

			if s2[i] == 'a' {
				ca--
			}
			if ca < 0 {
				f = false
				break
			}
		}

		for i := range s1 {
			if s2[i] == 'c' {
				cc++
			} else if (s1[i] == 'a' || s2[i] == 'a') && cc != 0 {
				f = false
				break
			}

			if s1[i] == 'c' {
				cc--
			}
			if cc < 0 {
				f = false
				break
			}
		}
		if !f || ca > 0 || cc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// s: ab -> ba ; bc -> cb
// t: ba -> ab ; cb -> bc
func solve(s, t []byte) bool {
	b1, b2 := 0, 0
	for _, v := range s {
		if v == 'b' {
			b1++
		}
	}
	for _, v := range t {
		if v == 'b' {
			b2++
		}
	}
	if b1 != b2 {
		return false
	}
	var i, j int
	for ; i < len(t); i++ {
		c := t[i]
		switch c {
		case 'a':
			for ; j < len(s); j++ {
				if s[j] == 'c' {
					return false
				}
				if s[j] == 'a' {
					if j > i {
						return false
					}
					j++
					break
				}
			}
		case 'c':
			for ; j < len(s); j++ {
				if s[j] == 'a' {
					return false
				}
				if s[j] == 'c' {
					if j < i {
						return false
					}
					j++
					break
				}
			}
		}
	}
	return true
}

func p1697c(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var q int
	var n int
	var s, t string
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &n)
		Fscan(in, &s, &t)
		if solve([]byte(s), []byte(t)) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	p1697c(os.Stdin, os.Stdout)
	// var (
	// a, b []byte
	// )
	// a = []byte("aa")
	// b = []byte("ab")
	// ans := solve(a, b)
	// fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scanln(&T)
	for tt := 0; tt < T; tt++ {
		var n int
		var a, b string
		fmt.Scanln(&n)
		fmt.Scanln(&a)
		fmt.Scanln(&b)

		a_count := 0
		b_count := 0

	    for i := 0; i < n; i++ {
		    if a[i] == 98 {
                a_count += 1
            }
            if b[i] == 98 {
                b_count += 1
            }
        }

        if a_count != b_count {
            fmt.Println("NO")
            continue;
		}
// 		fmt.Println("quack")
		j := 0
		printed := false
		for i := 0; i < n; i++ {
            if a[i] == 98 {
                continue;
            }
            for j < n && b[j] == 98 {
                j += 1
            }
		    //fmt.Printf("%d %d\n", i, j)
		    if a[i] != b[j] || (a[i] == 97 && i > j) || (a[i] == 99 && i < j) {
                fmt.Println("NO")
                printed = true
                break
            }
            j += 1
		}
		if !printed {
            fmt.Println("YES")
		}
// 		fmt.Println(a)
// 		fmt.Println(b)
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n int
		Fscan(in, &n)

		var sss, st string
		Fscan(in, &sss, &st)

		s := []rune(sss)
		t := []rune(st)

		fl := true
		nx := n - 1
		for cur := n - 1; cur >= 0; cur-- {
			for s[cur] != t[cur] {
				if t[cur]+1 == s[cur] {
					if cur-1 < nx {
						nx = cur - 1
					}
					for nx >= 0 && (s[nx] == s[cur]-1 || s[nx] == s[cur]) && s[nx] != t[cur] {
						nx--
					}

					if nx >= 0 && s[nx] == t[cur] && (s[nx] == s[cur]-1 || s[nx] == s[cur]) {
						s[cur], s[nx] = s[nx], s[cur]
					} else {
						fl = false
						break
					}

				} else {
					fl = false
					break
				}
			}

		}
		if fl {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var s1, t1 string
		Fscan(in, &s1, &t1)
		s, t := []byte(s1), []byte(t1)
		// cnt := make([]int, 26)
		// for i := 0; i < n; i++ {
		// 	cnt[int(s[i])-97]++
		// }
		// for i := 0; i < n; i++ {
		// 	cnt[int(t[i])-97]--
		// 	if cnt[int(t[i])-97] < 0 {
		// 		Fprintln(out, "NO")
		// 		return
		// 	}
		// }
		jump := make(map[int]int)
		for i := 0; i < n; i++ {
			if s[i] == t[i] {
				continue
			} else {
				if s[i] == 'c' || i+1 == n {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'a' && t[i] != 'b' {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'b' && t[i] != 'c' {
					Fprintln(out, "NO")
					return
				}
				var j int
				// if _, ok := jump[i]; ok {
				// 	j = jump[i]
				// } else {
				// 	j = i + 1
				// }
				j = i + 1
				for j < n && s[j] == s[i] {
					j++
				}
				if j < n && s[j] == t[i] {
					s[i], s[j] = s[j], s[i]
					jump[i+1] = j + 1
				} else {
					Fprintln(out, "NO")
					return
				}
			}
		}
		Fprintln(out, "Yes")
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var s1, t1 string
		Fscan(in, &s1, &t1)
		s, t := []byte(s1), []byte(t1)
		// cnt := make([]int, 26)
		// for i := 0; i < n; i++ {
		// 	cnt[int(s[i])-97]++
		// }
		// for i := 0; i < n; i++ {
		// 	cnt[int(t[i])-97]--
		// 	if cnt[int(t[i])-97] < 0 {
		// 		Fprintln(out, "NO")
		// 		return
		// 	}
		// }
		jump := make(map[int]int)
		for i := 0; i < n; i++ {
			if s[i] == t[i] {
				continue
			} else {
				if s[i] == 'c' || i+1 == n {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'a' && t[i] != 'b' {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'b' && t[i] != 'c' {
					Fprintln(out, "NO")
					return
				}
				var j int
				if _, ok := jump[i]; ok {
					j = jump[i]
				} else {
					j = i + 1
				}
				for j < n && s[j] == s[i] {
					j++
				}
				if j < n && s[j] == t[i] {
					s[i], s[j] = s[j], s[i]
					jump[i+1] = j + 1
				} else {
					Fprintln(out, "NO")
					return
				}
			}
		}
		Fprintln(out, "Yes")
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

import (
	"bufio"
	"fmt"
	"os"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	var s, t string
	fmt.Fscan(r, &s, &t)
	cnt := make([]int, 3)
	cnt_a := 0
	for i := range s {
		if s[i] == 'a' {
			cnt_a++
		} else if (s[i] == 'c'|| t[i] == 'c') && cnt_a != 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		if t[i] == 'a' {
			cnt_a--
		}
		if cnt_a < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		cnt[s[i]-'a']++
		cnt[t[i]-'a']--
	}
	cnt_c := 0
	for i:=n-1;i>=0;i-- {
		if s[i] == 'c' {
			cnt_c++
		} else if (s[i] == 'a' || t[i] == 'a') && cnt_c != 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		if t[i] == 'c' {
			cnt_c--
		}
		if cnt_c < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
	}
	if cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0 {
		fmt.Fprintln(w, "YES")
	} else {
		fmt.Fprintln(w, "NO")
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func CF1697C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	var s, t string
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s, &t)
		if strings.ReplaceAll(s, "b", "") != strings.ReplaceAll(t, "b", "") {
			Fprintln(out, "NO")
			continue
		}
		j := 0
		for i, c := range s {
			if c != 'b' {
				for t[j] == 'b' {
					j++
				}
				if i != j && c == 'c' == (i < j) {
					Fprintln(out, "NO")
					continue o
				}
				j++
			}
		}
		Fprintln(out, "YES")
	}
}

func main() { CF1697C(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strings"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

var n,m int
var tt int
var s,t string
func solve(){
	var l int
	Fscan(r,&l)
	Fscan(r,&s,&t)
	if strings.ReplaceAll(s,"b","") !=strings.ReplaceAll(t,"b",""){
		Fprintln(w,"NO")
		return
	}
	// 'a' means move_right
	// 'c' means move_left
	ptr_1,ptr_2:=0,0
	for ptr_1<l{
		if s[ptr_1]=='b'{
			ptr_1++
			continue
		}
		if t[ptr_2]=='b'{
			ptr_2++
			continue
		}
		if s[ptr_1]=='a' && ptr_1>ptr_2{
			Fprintln(w,"NO")
			return
		}
		if s[ptr_1]=='c' && ptr_1<ptr_2{
			Fprintln(w,"NO")
			return
		}
		ptr_1++
		ptr_2++
	}
	Fprintln(w,"YES")
	return
}

func main(){
	defer w.Flush()
	//Fscan(r,&n,&m)
	Fscan(r,&tt)

	for tt>=0{
		tt--
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====

acabcca
1020003

*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
			if i != 0 {
				aCnt[i] += aCnt[i-1]
			}
		}

		if s[i] == 'c' {
			cCnt[i]++
			if i != 0 {
				cCnt[i] += cCnt[i-1]
			}
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if s[i] == 'a' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[i] - cCnt[j]
			if s[j] == 'c' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
			if i != 0 {
				aCnt[i] += aCnt[i-1]
			}
		}

		if s[i] == 'c' {
			cCnt[i]++
			if i != 0 {
				cCnt[i] += cCnt[i-1]
			}
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[i] - cCnt[j]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
			if i != 0 {
				aCnt[i] += aCnt[i-1]
			}
		}

		if s[i] == 'c' {
			cCnt[i]++
			if i != 0 {
				cCnt[i] += cCnt[i-1]
			}
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[j] - cCnt[i]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
4
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
---
YES
NO
YES
NO
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {

		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			onlyC := true
			for l := i + 1; l <= j; l++ {
				if s[l] != 'c' {
					onlyC = false
				}
			}
			if !onlyC {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			onlyA := true
			for l := i - 1; l >= j; l-- {
				if s[l] != 'a' {
					onlyA = false
				}
			}
			if !onlyA {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else {
			i++
			j++
		}
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ca, cc int
		for i := range s1 {
			if s1[i] == 'a' {
				ca++
			} else if s1[i] == 'c' && s2[i] == 'c' || ca > 0 {
				f = false
				break
			}

			if s2[i] == 'a' {
				ca--
			}
			if ca < 0 {
				f = false
				break
			}
		}

		for i := range s1 {
			if s1[i] == 'c' {
				cc++
			} else if s1[i] == 'a' && s2[i] == 'c' || cc > 0 {
				f = false
				break
			}

			if s2[i] == 'c' {
				cc--
			}
			if cc < 0 {
				f = false
				break
			}
		}
		if !f || ca > 0 || cc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ab, bc int
		for i := range s1 {
			c1 := s1[i]
			c2 := s2[i]
			if c1 == 'a' && c2 == 'a' {
				if bc != 0 {
					f = false
					break
				}
			} else if c1 == 'c' && c2 == 'c' {
				if ab != 0 {
					f = false
					break
				}
			} else if c1 == 'a' && c2 == 'c' || c1 == 'c' && c2 == 'a' {
				f = false
				break
			} else if c1 == 'a' && c2 == 'b' {
				ab++
			} else if c1 == 'b' && c2 == 'a' {
				ab--
				if ab < 0 {
					f = false
					break
				}
			} else if c1 == 'b' && c2 == 'c' {
				bc++
			} else if c1 == 'c' && c2 == 'b' {
				bc--
				if bc < 0 {
					f = false
					break
				}
			}
		}

		if !f || ab > 0 || bc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ab, bc int
		for i := range s1 {
			c1 := s1[i]
			c2 := s2[i]
			if c1 == 'a' && c2 == 'a' {
				bc = 0
			} else if c1 == 'c' && c2 == 'c' {
				ab = 0
			} else if c1 == 'a' && c2 == 'c' || c1 == 'c' && c2 == 'a' {
				f = false
				break
			} else if c1 == 'a' && c2 == 'b' {
				ab++
			} else if c1 == 'b' && c2 == 'a' {
				ab--
				if ab < 0 {
					f = false
					break
				}
			} else if c1 == 'b' && c2 == 'c' {
				bc++
			} else if c1 == 'c' && c2 == 'b' {
				bc--
				if bc < 0 {
					f = false
					break
				}
			}
		}

		if !f || ab > 0 || bc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// s: ab -> ba ; bc -> cb
// t: ba -> ab ; cb -> bc
func solve(s, t []byte) bool {
	if len(s) == 1 {
		return s[0] == t[0]
	}
	for i := 0; i < len(s)-1; i++ {
		c1, c2 := s[i], s[i+1]
		t1, t2 := t[i], t[i+1]
		if c1 == t1 {
			continue
		}
		if c1 == 'a' && c2 == 'b' && t1 == 'b' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if c1 == 'b' && c2 == 'c' && t1 == 'c' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if t1 == 'b' && t2 == 'a' && c1 == 'a' {
			t[i], t[i+1] = t2, t1
			continue
		}
		if t1 == 'c' && t2 == 'b' && c1 == 'b' {
			t[i], t[i+1] = t2, t1
			continue
		}
		return false
	}
	return s[len(s)-1] == t[len(t)-1]
}

func p1697c(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var q int
	var n int
	var s, t string
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &n)
		Fscan(in, &s, &t)
		if solve([]byte(s), []byte(t)) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	p1697c(os.Stdin, os.Stdout)
	// var (
	// a, b []byte
	// )
	// a = []byte("aa")
	// b = []byte("ab")
	// ans := solve(a, b)
	// fmt.Println(ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// s: ab -> ba ; bc -> cb
// t: ba -> ab ; cb -> bc
func solve(s, t []byte) bool {
	if len(s) == 1 {
		return s[0] == t[0]
	}
	for i := 0; i < len(s)-1; i++ {
		c1, c2 := s[i], s[i+1]
		t1, t2 := t[i], t[i+1]
		if c1 == t1 {
			continue
		}
		if c1 == 'a' && c2 == 'b' && t1 == 'b' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if c1 == 'b' && c2 == 'c' && t1 == 'c' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if t1 == 'b' && t2 == 'a' && c1 == 'a' {
			t[i], t[i+1] = t2, t1
			continue
		}
		if t1 == 'c' && t2 == 'b' && c1 == 'b' {
			t[i], t[i+1] = t2, t1
			continue
		}
		return false
	}
	return true
}

func p1697c(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var q int
	var n int
	var s, t string
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &n)
		Fscan(in, &s, &t)
		if solve([]byte(s), []byte(t)) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	p1697c(os.Stdin, os.Stdout)
	// var (
	//     a, b []byte
	// )
	// a = []byte("bc")
	// b = []byte("cb")
	// ans := solve(a, b)
	// fmt.Println(ans)
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n int
		Fscan(in, &n)

		var sss, st string
		Fscan(in, &sss, &st)

		s := []rune(sss)
		t := []rune(st)

		fl := true
		for cur := n - 1; cur >= 0; cur-- {
			for s[cur] != t[cur] {
				if t[cur] < s[cur] {
					nx := cur - 1
					for nx >= 0 && (s[nx] == s[cur]-1 || s[nx] == s[cur]) && s[nx] != t[cur] {
						nx--
					}

					if nx >= 0 && s[nx] == t[cur] {
						s[cur], s[nx] = s[nx], s[cur]
					} else {
						fl = false
						break
					}

				} else {
					fl = false
					break
				}
			}

		}
		if fl {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	var s, t string
	fmt.Fscan(r, &s, &t)
	cnt := make([]int, 3)
	cnt_a := 0
	for i := range s {
		if s[i] == 'a' {
			cnt_a++
		} else if s[i] == 'c' {
			cnt_a = 0
		}
		if t[i] == 'a' {
			cnt_a--
		}
		if cnt_a < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		cnt[s[i]-'a']++
		cnt[t[i]-'a']--
	}
	cnt_c := 0
	for i:=n-1;i>=0;i-- {
		if s[i] == 'c' {
			cnt_c++
		} else if s[i] == 'a' {
			cnt_c = 0
		}
		if t[i] == 'c' {
			cnt_c--
		}
		if cnt_c < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
	}
	if cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0 {
		fmt.Fprintln(w, "YES")
	} else {
		fmt.Fprintln(w, "NO")
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}


Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.Johnny's truck has a gas tank that holds exactly n liters, and his tank is initially full. As he drives, the truck consumes exactly one liter per unit distance traveled. Moreover, there are m gas stations located at various points along the way to the district center. The i-th station is located at the point xi on the number line and sells an unlimited amount of fuel at a price of pi dollars per liter. Find the minimum cost Johnny must pay for fuel to successfully complete the delivery.

The first line of input contains three space separated integers d, n, and m (1 ≤ n ≤ d ≤ 109, 1 ≤ m ≤ 200 000) — the total distance to the district center, the volume of the gas tank, and the number of gas stations, respectively. Each of the next m lines contains two integers xi, pi (1 ≤ xi ≤ d - 1, 1 ≤ pi ≤ 106) — the position and cost of gas at the i-th gas station. It is guaranteed that the positions of the gas stations are distinct.

Print a single integer — the minimum cost to complete the delivery. If there is no way to complete the delivery, print -1.

NoteIn the first sample, Johnny's truck holds 4 liters. He can drive 3 units to the first gas station, buy 2 liters of gas there (bringing the tank to 3 liters total), drive 3 more units to the third gas station, buy 4 liters there to fill up his tank, and then drive straight to the district center. His total cost is 2·5 + 4·3 = 22 dollars.In the second sample, there is no way for Johnny to make it to the district center, as his tank cannot hold enough gas to take him from the latest gas station to the district center.

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type station struct {
	x, p int
}

type byX []station

func (s byX) Len() int           { return len(s) }
func (s byX) Less(i, j int) bool { return s[i].x < s[j].x }
func (s byX) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

type toFuel struct {
	price, amount int
}

type toFuelHeap []toFuel

func (s toFuelHeap) Len() int            { return len(s) }
func (s toFuelHeap) Less(i, j int) bool  { return s[i].price < s[j].price }
func (s toFuelHeap) Swap(i, j int)       { s[i], s[j] = s[j], s[i] }
func (s *toFuelHeap) Push(x interface{}) { *s = append(*s, x.(toFuel)) }
func (s *toFuelHeap) Pop() interface{} {
	*s = (*s)[:len(*s)-1]
	return nil
}

func main() {
	in.Split(bufio.ScanWords)

	d := readInt()
	n := readInt()
	m := readInt()

	st := make([]station, m+1, m+2)
	for i := range st[1:] {
		st[i+1].x = readInt()
		st[i+1].p = readInt()
	}
	sort.Sort(byX(st))
	st = append(st, station{d, -1})

	cur := n
	res := int64(0)
	totFueled := 0
	var tf toFuelHeap
	for i, s := range st[1:] {
		prev := st[i]
		if s.x-prev.x > n {
			fmt.Println(-1)
			return
		}
		for cur < s.x-prev.x {
			if len(tf) == 0 {
				fmt.Println(-1)
				return
			}
			fuel := (s.x - prev.x) - cur
			if fuel > tf[0].amount-totFueled {
				fuel = tf[0].amount - totFueled
			}
			if fuel > 0 {
				cur += fuel
				totFueled += fuel
				res += int64(tf[0].price) * int64(fuel)
			} else {
				heap.Pop(&tf)
			}
		}
		cur -= s.x - prev.x
		heap.Push(&tf, toFuel{price: s.p, amount: n - cur + totFueled})
	}
	fmt.Println(res)
}

// Codeforces 635 E
package main

import (
    "fmt"
    "bufio"
    "strconv"
    "strings"
    "os"
    "sort"
)

type zaprav struct {
    x int64
    p int64
}
// Array of zaprav.
type Zaps []zaprav

func (slice Zaps) Len() int {
	return len(slice)
}
func (slice Zaps) Less(i, j int) bool {
	return slice[i].x < slice[j].x;
}
func (slice Zaps) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

type portion struct {
    vol int64
    p int64
}

var d,n int64
var m int
var z Zaps
var bak []portion // portions of gaz, low to high price
var np int        // number of portions
var cost int64
var stopped bool

func spend(di int64) {
    //fmt.Printf("beg spend di = %d\n",di)
    var nused int
    for i:=0; i<np; i++ {
        if (di == 0) {
            break
        } else if (di >= bak[i].vol) {
            di -= bak[i].vol
            cost += bak[i].vol * bak[i].p
            bak[i].vol = 0
            nused ++;
        } else {
            bak[i].vol -= di
            cost += di * bak[i].p
            di = 0
        }
    }
    for i:=nused; i<np; i++ {
        bak[i-nused] = bak[i]
    }
    np -= nused
    //fmt.Printf("end of spend, di = %d\n",di)
    if (di>0) {
        stopped = true
    }
}

// replace fuel more expensive than p with p.
func replace(p int64, di int64) {
    var vrep int64
    for i:=np-1; i>=0; i-- {
        if bak[i].p <= p {
            break;
        } else {
            vrep += bak[i].vol
            bak[i].vol = 0
            np = i
        }
    }
    // adding bought fuel
    bak[np].p = p
    bak[np].vol = vrep + di
    np++
    //fmt.Printf("replaced %d\n",di)
}

func miconv(s string) int64 {
    i,err := strconv.Atoi(s)
    if err != nil {
        fmt.Println("error in converting " + s)
    }
    iret := int64(i)
    return iret
}

func main() {
    // reading n
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    d = miconv(ss[0])
    n = miconv(ss[1])
    m = int(miconv(ss[2]))

    stopped = false
    z = Zaps(make([]zaprav, m))
    for i:=0; i<m; i++ {
        s,_ = in.ReadString('\n')
        ss := strings.Split(strings.Trim(s," \n\r")," ")
        z[i].x = miconv(ss[0])
        z[i].p = miconv(ss[1])
		if err != nil {
		    fmt.Println("read failure", err)
		}
    }

    // sort zapravki by x
    sort.Sort(z)
    //fmt.Println(z)

    // driving
    var xs int64
    var di int64
    bak = make([]portion, m+1)
    bak[0].vol = n
    bak[0].p = 0
    np = 1
    for i:=0; i<m; i++ {
        var di = z[i].x - xs
        xs = z[i].x
        spend(di)
        if stopped {
            break
        }
        replace(z[i].p, di)
    }
    di = d - xs
    spend(di)
    if stopped {
        cost = -1
    }

	// print result
	fmt.Printf("%d\n", cost)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type station struct {
	x, p int
}

type byX []station

func (s byX) Len() int           { return len(s) }
func (s byX) Less(i, j int) bool { return s[i].x < s[i].x }
func (s byX) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

type toFuel struct {
	price, amount int
}

type toFuelHeap []toFuel

func (s toFuelHeap) Len() int            { return len(s) }
func (s toFuelHeap) Less(i, j int) bool  { return s[i].price < s[j].price }
func (s toFuelHeap) Swap(i, j int)       { s[i], s[j] = s[j], s[i] }
func (s *toFuelHeap) Push(x interface{}) { *s = append(*s, x.(toFuel)) }
func (s *toFuelHeap) Pop() interface{} {
	*s = (*s)[:len(*s)-1]
	return nil
}

func main() {
	in.Split(bufio.ScanWords)

	d := readInt()
	n := readInt()
	m := readInt()

	st := make([]station, m+1, m+2)
	for i := range st[1:] {
		st[i+1].x = readInt()
		st[i+1].p = readInt()
	}
	sort.Sort(byX(st))
	st = append(st, station{d, -1})

	cur := n
	res := int64(0)
	totFueled := 0
	var tf toFuelHeap
	for i, s := range st[1:] {
		prev := st[i]
		if s.x-prev.x > n {
			fmt.Println(-1)
			return
		}
		for cur < s.x-prev.x {
			if len(tf) == 0 {
				fmt.Println(-1)
				return
			}
			fuel := (s.x - prev.x) - cur
			if fuel > tf[0].amount-totFueled {
				fuel = tf[0].amount - totFueled
			}
			if fuel > 0 {
				cur += fuel
				totFueled += fuel
				res += int64(tf[0].price) * int64(fuel)
			} else {
				heap.Pop(&tf)
			}
		}
		cur -= s.x - prev.x
		heap.Push(&tf, toFuel{price: s.p, amount: n - cur + totFueled})
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type station struct {
	x, p int
}

type byX []station

func (s byX) Len() int           { return len(s) }
func (s byX) Less(i, j int) bool { return s[i].x < s[i].x }
func (s byX) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

type toFuel struct {
	price, amount int
}

type toFuelHeap []toFuel

func (s toFuelHeap) Len() int            { return len(s) }
func (s toFuelHeap) Less(i, j int) bool  { return s[i].price < s[j].price }
func (s toFuelHeap) Swap(i, j int)       { s[i], s[j] = s[j], s[i] }
func (s *toFuelHeap) Push(x interface{}) { *s = append(*s, x.(toFuel)) }
func (s *toFuelHeap) Pop() interface{} {
	*s = (*s)[:len(*s)-1]
	return nil
}

func main() {
	in.Split(bufio.ScanWords)

	d := readInt()
	n := readInt()
	m := readInt()

	st := make([]station, m+1, m+2)
	for i := range st[1:] {
		st[i+1].x = readInt()
		st[i+1].p = readInt()
	}
	sort.Sort(byX(st))
	st = append(st, station{d, -1})

	cur := n
	res := int64(0)
	totFueled := 0
	var tf toFuelHeap
	for i, s := range st[1:] {
		prev := st[i]
		for cur < s.x-prev.x {
			if len(tf) == 0 {
				fmt.Println(-1)
				return
			}
			fuel := (s.x - prev.x) - cur
			if fuel > tf[0].amount-totFueled {
				fuel = tf[0].amount - totFueled
			}
			if fuel > 0 {
				cur += fuel
				totFueled += fuel
				res += int64(tf[0].price) * int64(fuel)
			} else {
				heap.Pop(&tf)
			}
		}
		cur -= s.x - prev.x
		heap.Push(&tf, toFuel{price: s.p, amount: n - cur + totFueled})
	}
	fmt.Println(res)
}

// Codeforces 635 E
package main

import (
    "fmt"
    "bufio"
    "strconv"
    "strings"
    "os"
)

type zaprav struct {
    x int64
    p int64
}
type portion struct {
    vol int64
    p int64
}

var d,n int64
var m int
var z []zaprav
var bak []portion // portions of gaz, low to high price
var np int        // number of portions
var cost int64
var stopped bool

func spend(di int64) {
    //fmt.Printf("beg spend di = %d\n",di)
    var nused int
    for i:=0; i<np; i++ {
        if (di == 0) {
            break
        } else if (di >= bak[i].vol) {
            di -= bak[i].vol
            cost += bak[i].vol * bak[i].p
            bak[i].vol = 0
            nused ++;
        } else {
            bak[i].vol -= di
            cost += di * bak[i].p
            di = 0
        }
    }
    for i:=nused; i<np; i++ {
        bak[i-nused] = bak[i]
    }
    np -= nused
    //fmt.Printf("end of spend, di = %d\n",di)
    if (di>0) {
        stopped = true
    }
}

// replace fuel more expensive than p with p.
func replace(p int64, di int64) {
    var vrep int64
    for i:=np-1; i>=0; i-- {
        if bak[i].p <= p {
            break;
        } else {
            vrep += bak[i].vol
            bak[i].vol = 0
            np = i
        }
    }
    // adding bought fuel
    bak[np].p = p
    bak[np].vol = vrep + di
    np++
    //fmt.Printf("replaced %d\n",di)
}

func miconv(s string) int64 {
    i,err := strconv.Atoi(s)
    if err != nil {
        fmt.Println("error in converting " + s)
    }
    iret := int64(i)
    return iret
}

func main() {
    // reading n
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    d = miconv(ss[0])
    n = miconv(ss[1])
    m = int(miconv(ss[2]))

    stopped = false
    z = make([]zaprav, m)
    for i:=0; i<m; i++ {
        s,_ = in.ReadString('\n')
        ss := strings.Split(strings.Trim(s," \n\r")," ")
        z[i].x = miconv(ss[0])
        z[i].p = miconv(ss[1])
		if err != nil {
		    fmt.Println("read failure", err)
		}
    }

    // driving
    var xs int64
    var di int64
    bak = make([]portion, m+1)
    bak[0].vol = n
    bak[0].p = 0
    np = 1
    for i:=0; i<m; i++ {
        var di = z[i].x - xs
        xs = z[i].x
        spend(di)
        if stopped {
            cost = -1
            break
        }
        replace(z[i].p, di)
    }
    di = d - xs
    spend(di)

	// print result
	fmt.Printf("%d\n", cost)
}

// Codeforces 635 E
package main

import (
    "fmt"
    "bufio"
    "strconv"
    "strings"
    "os"
    "sort"
)

type zaprav struct {
    x int64
    p int64
}
// Array of zaprav.
type Zaps []zaprav

func (slice Zaps) Len() int {
	return len(slice)
}
func (slice Zaps) Less(i, j int) bool {
	return slice[i].x < slice[j].x;
}
func (slice Zaps) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

type portion struct {
    vol int64
    p int64
}

var d,n int64
var m int
var z Zaps
var bak []portion // portions of gaz, low to high price
var np int        // number of portions
var cost int64
var stopped bool

func spend(di int64) {
    //fmt.Printf("beg spend di = %d\n",di)
    var nused int
    for i:=0; i<np; i++ {
        if (di == 0) {
            break
        } else if (di >= bak[i].vol) {
            di -= bak[i].vol
            cost += bak[i].vol * bak[i].p
            bak[i].vol = 0
            nused ++;
        } else {
            bak[i].vol -= di
            cost += di * bak[i].p
            di = 0
        }
    }
    for i:=nused; i<np; i++ {
        bak[i-nused] = bak[i]
    }
    np -= nused
    //fmt.Printf("end of spend, di = %d\n",di)
    if (di>0) {
        stopped = true
    }
}

// replace fuel more expensive than p with p.
func replace(p int64, di int64) {
    var vrep int64
    for i:=np-1; i>=0; i-- {
        if bak[i].p <= p {
            break;
        } else {
            vrep += bak[i].vol
            bak[i].vol = 0
            np = i
        }
    }
    // adding bought fuel
    bak[np].p = p
    bak[np].vol = vrep + di
    np++
    //fmt.Printf("replaced %d\n",di)
}

func miconv(s string) int64 {
    i,err := strconv.Atoi(s)
    if err != nil {
        fmt.Println("error in converting " + s)
    }
    iret := int64(i)
    return iret
}

func main() {
    // reading n
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    d = miconv(ss[0])
    n = miconv(ss[1])
    m = int(miconv(ss[2]))

    stopped = false
    z = Zaps(make([]zaprav, m))
    for i:=0; i<m; i++ {
        s,_ = in.ReadString('\n')
        ss := strings.Split(strings.Trim(s," \n\r")," ")
        z[i].x = miconv(ss[0])
        z[i].p = miconv(ss[1])
		if err != nil {
		    fmt.Println("read failure", err)
		}
    }

    // sort zapravki by x
    sort.Sort(z)

    // driving
    var xs int64
    var di int64
    bak = make([]portion, m+1)
    bak[0].vol = n
    bak[0].p = 0
    np = 1
    for i:=0; i<m; i++ {
        var di = z[i].x - xs
        xs = z[i].x
        spend(di)
        if stopped {
            cost = -1
            break
        }
        replace(z[i].p, di)
    }
    di = d - xs
    spend(di)

	// print result
	fmt.Printf("%d\n", cost)
}


The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and $$$n$$$ cities in a circle around the capital. The capital already has a good network coverage (so the government ignores it), but the $$$i$$$-th city contains $$$a_i$$$ households that require a connection.The government designed a plan to build $$$n$$$ network stations between all pairs of neighboring cities which will maintain connections only for these cities. In other words, the $$$i$$$-th network station will provide service only for the $$$i$$$-th and the $$$(i + 1)$$$-th city (the $$$n$$$-th station is connected to the $$$n$$$-th and the $$$1$$$-st city).All network stations have capacities: the $$$i$$$-th station can provide the connection to at most $$$b_i$$$ households.Now the government asks you to check can the designed stations meet the needs of all cities or not — that is, is it possible to assign each household a network station so that each network station $$$i$$$ provides the connection to at most $$$b_i$$$ households.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 10^6$$$) — the number of cities and stations. The second line of each test case contains $$$n$$$ integers ($$$1 \le a_i \le 10^9$$$) — the number of households in the $$$i$$$-th city. The third line of each test case contains $$$n$$$ integers ($$$1 \le b_i \le 10^9$$$) — the capacities of the designed stations. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^6$$$.

For each test case, print YES, if the designed stations can meet the needs of all cities, or NO otherwise (case insensitive).

NoteIn the first test case:   the first network station can provide $$$2$$$ connections to the first city and $$$1$$$ connection to the second city;  the second station can provide $$$2$$$ connections to the second city and $$$1$$$ connection to the third city;  the third station can provide $$$3$$$ connections to the third city. In the second test case:   the $$$1$$$-st station can provide $$$2$$$ connections to the $$$1$$$-st city;  the $$$2$$$-nd station can provide $$$3$$$ connections to the $$$2$$$-nd city;  the $$$3$$$-rd station can provide $$$3$$$ connections to the $$$3$$$-rd city and $$$1$$$ connection to the $$$1$$$-st station. In the third test case, the fourth city needs $$$5$$$ connections, but the third and the fourth station has $$$4$$$ connections in total.

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
)

var (
	inn = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)
	//prep
	for tt := rd(); tt > 0; tt-- {
		n := rd()
		a, b := make([]int64, n), make([]int64, n)
		var suma, sumb int64
		for i := range a {
			a[i] = rdll()
			suma += a[i]
		}
		for i := range b {
			b[i] = rdll()
			sumb += b[i]
		}
		ok := true
		if suma > sumb {
			ok = false
		}
		var s int64
		mx := int64(-1e18)
		for i := 0; i < 2*n; i++ {
			s += int64(b[i%n]) - int64(a[i%n])
			mx = maxll(mx, s-b[i%n])
			if s < mx {
				ok = false
				break
			}
		}
		if ok {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

//-------------------template------------------
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func maxll(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	x, _ = strconv.Atoi(string(inn.Bytes()))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	x, _ = strconv.ParseInt(string(inn.Bytes()), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}


The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the i-th computer it was ai kilobits per second.There will be k participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible.The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least k of n computers had the same data transfer speed and the data transfer speed on these computers was as large as possible?

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of n integers: a1, a2, ..., an (16 ≤ ai ≤ 32768); number ai denotes the maximum data transfer speed on the i-th computer.

Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.

NoteIn the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
  "sort"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, k := getI(), getI()
  speeds := make([]int, n)
  for i := 0; i < n; i++ {
    speeds[i] = getI()
  }
  sort.Ints(speeds)
  pos, same := n, 0
  for same < k {
    pos--
    seek := pos
    for seek > 0 && speeds[seek-1] == speeds[pos] {
      seek--
    }
    same += pos-seek+1
    pos = seek
  }
  writer.WriteString(fmt.Sprintf("%d\n", speeds[pos]))
}

//412B
package main
import "fmt"

func main() {
	var nn, kk, x, y int32
	var aa[105]int32
	fmt.Scan(&nn, &kk)
	x=0
	for i:=1; int32(i)<=nn; i++ {
		fmt.Scan(&aa[i])
		x=x+aa[i]
	}
	for i:=1; int32(i)<=nn; i++ {
		for j:=i+1; int32(j)<=nn; j++ {
			if aa[i]>aa[j] {
				y=aa[j]
				aa[j]=aa[i]
				aa[i]=y
			}
		}
	}
	fmt.Println(aa[nn-kk+1])
}

package main

import (
    "fmt"
    "os"
    "sort"
)

func PrepareInput() (int, int, []int) {
    var totalComputers int
    var totalParticipants int

    fmt.Fscan(os.Stdin, &totalComputers)
    fmt.Fscan(os.Stdin, &totalParticipants)

    computers := make([]int, totalComputers)

    for i := 0; i < totalComputers; i++ {
        fmt.Fscan(os.Stdin, &computers[i])
    }

    return totalComputers, totalParticipants, computers
}

func LowerToMaxPossibleSpeed(totalComputers int, totalParticipants int , computers []int) int {
    var computerCount map[int]int
    var maxAllowed int

    computerCount = make(map[int]int)

    for i := 0; i < totalComputers; i += 1 {
        computerCount[computers[i]] = 0
    }

    for i := 0; i < totalComputers; i += 1 {
        computerCount[computers[i]] += 1
    }

    keys := make([]int, len(computerCount))

    i := 0
    for k := range computerCount {
        keys[i] = k
        i += 1
    }

    sort.Sort(sort.Reverse(sort.IntSlice(keys)))

    maxAllowed = 0

    for i := 0; i < len(computerCount); i++ {
        if i == len(computerCount) - 1 {
            maxAllowed = keys[i]
            break
        }

        if computerCount[keys[i]] >= totalParticipants {
            maxAllowed = keys[i]
            break
        }

        computerCount[keys[i+1]] += computerCount[keys[i]]
    }

    return maxAllowed
}

func main() {
    totalComputers, totalParticipants, computers := PrepareInput()
    fmt.Println(LowerToMaxPossibleSpeed(totalComputers, totalParticipants, computers))
}

// 412B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Print(a[n-k])
}