-----Problem Statement-----
A classroom has several students, half of whom are boys and half of whom are girls. You need to arrange all of them in a line for the morning assembly such that the following conditions are satisfied:
- The students must be in order of non-decreasing height.
- Two boys or two girls must not be adjacent to each other.
You have been given the heights of the boys in the array $b$ and the heights of the girls in the array $g$. Find out whether you can arrange them in an order which satisfies the given conditions. Print "YES" if it is possible, or "NO" if it is not.
For example, let's say there are $n = 3$ boys and $n = 3$ girls, where the boys' heights are $b = [5, 3, 8]$ and the girls' heights are $g = [2, 4, 6]$. These students can be arranged in the order $[g_0, b_1, g_1, b_0, g_2, b_2]$, which is $[2, 3, 4, 5, 6, 8]$. Because this is in order of non-decreasing height, and no two boys or two girls are adjacent to each other, this satisfies the conditions. Therefore, the answer is "YES".

-----Input-----
- The first line contains an integer, $t$, denoting the number of test cases.
- The first line of each test case contains an integer, $n$, denoting the number of boys and girls in the classroom.
- The second line of each test case contains $n$ space separated integers, $b_1,b_2, ... b_n$, denoting the heights of the boys.
- The second line of each test case contains $n$ space separated integers, $g_1,g_2,... g_n$, denoting the heights of the girls.

-----Output-----
Print exactly $t$ lines. In the $i^{th}$ of them, print a single line containing "$YES$" without quotes if it is possible to arrange the students in the $i^{th}$ test case, or "$NO$" without quotes if it is not.

-----Constraints-----
- $1 \leq t \leq 10$
- $1 \leq n \leq 100$
- $1 \leq b_i, g_i \leq 100$

-----Sample Input-----
1
2
1 3
2 4

-----Sample Output-----
YES

-----EXPLANATION-----
The following arrangement would satisfy the given conditions: $[b_1, g_1, b_2, g_2]$. This is because the boys and girls and separated, and the height is in non-decreasing order.

Difficulty: interview

Starter code:

Solutions:
for u in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    d=list(map(int,input().split()))
    ka=[]
    k=[]
    l.sort()
    d.sort()
    for i in range(n):
        ka.append(d[i])
        ka.append(l[i])
    for i in range(n):
        k.append(l[i])
        k.append(d[i])
    if(ka==sorted(ka)):
        print("YES")
    elif(k==sorted(k)):
        print("YES")
    else:
        print("NO")


for _ in range(int(input())):
    n = int(input())
    b = list(map(int, input().split()))
    g = list(map(int, input().split()))
    b.sort()
    g.sort()
    ans = []
    flag = 0
    val = 0
    st = 0
    if (b[0] < g[0]):
        f = 'b'
        ans.append(min(b[0], g[0]))
        ans.append(max(b[0], g[0]))
        st = 1
    elif g[0] > b[0]:
        f = 'g'
        st = 1
        ans.append(min(b[0], g[0]))
        ans.append(max(b[0], g[0]))
    else:
        for i in range(n):
            if (b[i] < g[i]):
                f = 'b'
                st = i
                break
            elif g[i] < b[i]:
                st = i
                f = 'g'
                break
            ans.append(b[i])
            ans.append(g[i])
    if (len(ans) == (2 * n)):
        val = 1
    if (n >= 2 and val != 1):
        for i in range(st, n):
            if (f == 'b'):
                ans.append(b[i])
                ans.append(g[i])
            else:
                ans.append(g[i])
                ans.append(b[i])

    for i in range(1, len(ans)):
        if (ans[i] < ans[i - 1]):
            flag = 1
            break
    if (flag):
        print('NO')
    else:
        print("YES")




# cook your dish here
for i in range(int(input())):
    n = int(input())
    b = [int(x) for x in input().split()]
    g = [int(x) for x in input().split()]
    boy = sorted(b)
    girl = sorted(g)
    f = 0
    for k in range(n-1):
        
        if girl[k] < boy[k]:
            if girl[k+1] < boy[k]:
                f = 1
                break
            
            
        elif girl[k] > boy[k]:
            
            if girl[k] > boy[k+1]:
                f = 1
                break
    if girl[0] < boy[0]:
        if girl[n-1] > boy[n-1]:
            f = 1
    elif boy[0] < girl[0]:
        if boy[n-1] > girl[n-1]:
            f = 1
        
                
    if f == 1:
        print("NO")
    else:
        print("YES")


# cook your dish here
for i in range(int(input())):
    n=int(input())
    lst1=list(map(int,input().split()))
    lst2=list(map(int,input().split()))
    lst1.sort()
    lst2.sort()
    lst12=[]
    lst21=[]
    for i in range(n):
        lst12.append(lst1[i])
        lst12.append(lst2[i])
        lst21.append(lst2[i])
        lst21.append(lst1[i])
    #print(lst12)
    #print(lst21)
    lst3=lst1+lst2
    lst3.sort()
    if(lst12==lst3 or lst21==lst3):
        print("YES")
    else:
        print("NO")

# cook your dish here
def check(x,y,n):
    k = 0
    for i in range(0,n-1):
        if(x[i] >= y[i] and x[i] <= y[i+1]):
            k += 1
        else: 
            break
    if(k == n-1):
        if(x[-1] >= y[-1]):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

t = int(input())
for _ in range(t):
    n = int(input())
    b = list(map(int, input().split()))
    g = list(map(int, input().split()))
    b.sort()
    g.sort()
    z = 0
    if(g[0] < b[0]):
        check(b,g,n)
    elif(g[0] > b[0]):
        check(g,b,n)
    else:
        for i in range(n):
            if(b[i] > g[i]):
                check(b[i:], g[i:], n-i)
                break
            elif(b[i] < g[i]):
                check(g[i:], b[i:], n-i)
                break
            z += 1
        if(z == n):
            print("YES")

for _ in range(int(input())):
    n = int(input())
    b = sorted(list(map(int, input().split())))
    g = sorted(list(map(int, input().split())))
    b1,g1 = [],[]
    B,G = 0,0
    count = 0
    for i in range(n):
        b1.append(b[i])
        b1.append(g[i])
        g1.append(g[i])
        g1.append(b[i])
    for i in range((n*2)-1):
        if b1[i] <= b1[i+1]:
            B += 1
        if g1[i] <= g1[i+1]:
            G += 1
    if B == (n*2)-1 or G == (n*2)-1:
        print("YES")
    else:
        print("NO")

import re

for _ in range(int(input())):
    n = int(input())
    b = list(map(int,input().split()))
    g = list(map(int,input().split()))
    a = sorted(b)
    b = sorted(g)
    i,j = 0,0
    x = ""
    cutt = 2

    while i<n and j<n:
        if a[i]<b[j]:
            x+="b"
            i+=1
        elif a[i]==b[j]:
            if len(x)==0:
                x+="b"
                cutt=1
                i+=1
            elif x[-1]=="b":
                x+="g"
                j+=1
            else:
                x+="b"
                i+=1

        else:
            x+="g"
            j+=1

    while i<n:
        x+="b"
        i+=1
    while j<n:
        x+="g"
        j+=1


    w = re.findall(r"[b]{2}",x)
    t = re.findall(r"[g]{2}",x)

    if (w or t) and cutt ==1:
        i=0

        n=len(a)
        j=0
        x=""

        while i<n and j<n:

            if a[i]<b[j]:
                x+="b"
                i+=1
            elif a[i]==b[j]:
                if len(x)==0:
                    x+="g"

                    j+=1
                elif x[-1]=="b":
                    x+="g"
                    j+=1
                else:
                    x+="b"
                    i+=1

            else:
                x+="g"
                j+=1

        while i<n:
            x+="b"
            i+=1
        while j<n:
            x+="g"
            j+=1


        w = re.findall(r"[b]{2}",x)
        t = re.findall(r"[g]{2}",x)
        if w or t:
            print("NO")
        else:
            print('YES')
            
    elif w or t:
        print("NO")
    else:
        print("YES")

import sys     
import math as mt
import bisect
input=sys.stdin.readline
t=int(input())
#t=1  
   
def solve(l3,l4):
    cnt=0
    l5=[]
    for i in range(n):
        l5.append(l3[i])
        l5.append(l4[i])
    
    for i in range(1,len(l5)):
        if l5[i]<l5[i-1]:
            cnt=1
    if cnt==0:
        return True
    
    return False    
            
   
for _ in range(t):
    n=int(input())
    #n,k=map(int,input().split())
    #x,y,k=map(int,input().split())
    #n,h=(map(int,input().split()))
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    l1.sort()
    l2.sort()
    if (solve(l1,l2) or solve(l2,l1)):
        print("YES")
    else:
        print("NO")
                        


def checkAccending(li):
	for i in range(len(li)-1):
		if li[i]>li[i+1]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	b = sorted(int(i) for i in input().split())
	g = sorted(int(i) for i in input().split())
	
	sb=[]
	sg=[]
	
	for i in range(n):
		sb.append(b[i])
		sb.append(g[i])
		
		sg.append(g[i])
		sg.append(b[i])
	
	if checkAccending(sb) or checkAccending(sg):
		print('YES')
	else:
		print('NO')

# cook your dish here
T=int(input())
for _ in range(T):
    n=int(input())
    b=list(map(int,input().split()))
    g=list(map(int,input().split()))
    my_list=b+g
    my_list.sort()
    b1=b.copy()
    g1=g.copy()
    lim=2*n
    k1,k2=1,1
    for i in range(lim):
        if my_list[i] in b and i%2==0:
            b.remove(my_list[i])
        elif my_list[i] in g and i%2:
            g.remove(my_list[i])
        else:
            k1=0
            break
    for i in range(lim):
        if my_list[i] in g1 and i%2==0:
            g1.remove(my_list[i])
        elif my_list[i] in b1 and i%2:
            b1.remove(my_list[i])
        else:
            k2=0
            break
    if k1 or k2:
        print('YES')
    else:
        print('NO')

def fun(j,n):
	nonlocal b
	nonlocal g
	active=True
	if b[j]>g[j]:
		for i in range(j,n):
			if g[i]>b[i] or (i>0 and b[i-1]>g[i]):
				active=False
				return False
	else:
		for i in range(j,n):
			if g[i]<b[i] or (i>0 and g[i-1]>b[i]):
				active=False
				return False
	return True
ls=[]
t=int(input())
for z in range(t):
	n=int(input())
	b=list(map(int,input().rstrip().split()))
	g=list(map(int,input().rstrip().split()))
	b.sort()
	g.sort()
	i=0
	active=True
	while i<n and b[i]==g[i]:
		i+=1
	if i<n:
		active=fun(i,n)
	if active==True:
		ls.append("YES")
	else:
		ls.append("NO")

for i in ls:
	print(i)


import re

for _ in range(int(input())):
    n = int(input())
    b = list(map(int,input().split()))
    g = list(map(int,input().split()))
    a = sorted(b)
    b = sorted(g)
    i,j = 0,0
    x = ""
    cutt = 2

    while i<n and j<n:
        if a[i]<b[j]:
            x+="b"
            i+=1
        elif a[i]==b[j]:
            if len(x)==0:
                x+="b"
                cutt=1
                i+=1
            elif x[-1]=="b":
                x+="g"
                j+=1
            else:
                x+="b"
                i+=1

        else:
            x+="g"
            j+=1

    while i<n:
        x+="b"
        i+=1
    while j<n:
        x+="g"
        j+=1


    w = re.findall(r"[b]{2}",x)
    t = re.findall(r"[g]{2}",x)

    if (w or t) and cutt ==1:
        i=0

        n=len(a)
        j=0
        x=""

        while i<n and j<n:

            if a[i]<b[j]:
                x+="b"
                i+=1
            elif a[i]==b[j]:
                if len(x)==0:
                    x+="g"

                    j+=1
                elif x[-1]=="b":
                    x+="g"
                    j+=1
                else:
                    x+="b"
                    i+=1

            else:
                x+="g"
                j+=1

        while i<n:
            x+="b"
            i+=1
        while j<n:
            x+="g"
            j+=1


        w = re.findall(r"[b]{2}",x)
        t = re.findall(r"[g]{2}",x)
        if w or t:
            print("NO")
        else:
            print('YES')
            
    elif w or t:
        print("NO")
    else:
        print("YES")

# cook your dish here
for i in range(int(input())):
    n=int(input())
    lst1=list(map(int,input().split()))
    lst2=list(map(int,input().split()))
    lst1.sort()
    lst2.sort()
    lst12=[]
    lst21=[]
    for i in range(n):
        lst12.append(lst1[i])
        lst12.append(lst2[i])
        lst21.append(lst2[i])
        lst21.append(lst1[i])
    #print(lst12)
    #print(lst21)
    lst3=lst1+lst2
    lst3.sort()
    if(lst12==lst3 or lst21==lst3):
        print("YES")
    else:
        print("NO")


try:
    for _ in range(int(input())):
        n=int(input())
        b=list(map(int,input().split()))
        g=list(map(int,input().split()))
        b.sort()
        g.sort()
        i=0
        flag1,flag2=1,1
        new1=[]
        new2=[]
        while i<n:
            new1.append(b[i])
            new1.append(g[i])
            i+=1
        for i in range(1,len(new1)):
            if new1[i]<new1[i-1]:
                flag1=0
                break
        i=0
        while i<n:
            new2.append(g[i])
            new2.append(b[i])
            i+=1
        for i in range(1,len(new2)):
            if new2[i]<new2[i-1]:
                flag2=0
                break
        if flag1 or flag2:
            print("YES")
        else:
            print("NO")
except:
    pass


# cook your dish here
a = int(input())
for i in range(a):
    n = int(input())
    b = list(map(int,input().split()))
    g = list(map(int,input().split()))
    b.sort()
    g.sort()
    h1 =[]
    h2= []
    for i in range(n):
        h1.append(b[i])
        h1.append(g[i])
    for i in range(n):
        h2.append(g[i])
        h2.append(b[i])
    if h1 == sorted(h1) or h2 ==  sorted(h2):
        print("YES")
    else:
        print("NO")


for _ in range(int(input())):
	N = int(input());barr = sorted(list(map(int , input().split())));garr = sorted(list(map(int , input().split())));tarr = barr + garr;ans1 = [0]*(N*2);ans2 = [0]*(N*2);tarr.sort();j = 0
	for i in range(N): ans1[j] += garr[i];ans1[j + 1] += barr[i];ans2[j] += barr[i];ans2[j + 1] += garr[i];j += 2
	print("YES") if(ans1 == tarr or ans2 == tarr) else print("NO")


try:
    for _ in range(int(input())):
        n=int(input())
        b=list(map(int,input().split()))
        g=list(map(int,input().split()))
        b.sort()
        g.sort()
        i=0
        flag1,flag2=1,1
        new1=[]
        new2=[]
        while i<n:
            new1.append(b[i])
            new1.append(g[i])
            i+=1
        for i in range(1,len(new1)):
            if new1[i]<new1[i-1]:
                flag1=0
                break
        i=0
        while i<n:
            new2.append(g[i])
            new2.append(b[i])
            i+=1
        for i in range(1,len(new2)):
            if new2[i]<new2[i-1]:
                flag2=0
                break
        if flag1 or flag2:
            print("YES")
        else:
            print("NO")
except:
    pass


try:
    for _ in range(int(input())):
        n=int(input())
        b=list(map(int,input().split()))
        g=list(map(int,input().split()))
        b.sort()
        g.sort()
        i=0
        flag1,flag2=1,1
        new1=[]
        new2=[]
        while i<n:
            new1.append(b[i])
            new1.append(g[i])
            i+=1
        for i in range(1,len(new1)):
            if new1[i]<new1[i-1]:
                flag1=0
                break
        i=0
        while i<n:
            new2.append(g[i])
            new2.append(b[i])
            i+=1
        for i in range(1,len(new2)):
            if new2[i]<new2[i-1]:
                flag2=0
                break
        if flag1 or flag2:
            print("YES")
        else:
            print("NO")
except:
    pass

# cook your dish here
a = int(input())
for i in range(a):
    n = int(input())
    b = list(map(int,input().split()))
    g = list(map(int,input().split()))
    b.sort()
    g.sort()
    h1 =[]
    h2= []
    for i in range(n):
        h1.append(b[i])
        h1.append(g[i])
    for i in range(n):
        h2.append(g[i])
        h2.append(b[i])
    if h1 == sorted(h1) or h2 ==  sorted(h2):
        print("YES")
    else:
        print("NO")


try:
    for _ in range(int(input())):
        n=int(input())
        b=list(map(int,input().split()))
        g=list(map(int,input().split()))
        b.sort()
        g.sort()
        i=0
        flag1,flag2=1,1
        new1=[]
        new2=[]
        while i<n:
            new1.append(b[i])
            new1.append(g[i])
            i+=1
        for i in range(1,len(new1)):
            if new1[i]<new1[i-1]:
                flag1=0
                break
        i=0
        while i<n:
            new2.append(g[i])
            new2.append(b[i])
            i+=1
        for i in range(1,len(new2)):
            if new2[i]<new2[i-1]:
                flag2=0
                break
        if flag1 or flag2:
            print("YES")
        else:
            print("NO")
except:
    pass

def check(x,y,n):
    k = 0
    for i in range(0,n-1):
        if(x[i] >= y[i] and x[i] <= y[i+1]):
            k += 1
        else: 
            break
    if(k == n-1):
        if(x[-1] >= y[-1]):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

t = int(input())
for _ in range(t):
    n = int(input())
    b = list(map(int, input().split()))
    g = list(map(int, input().split()))
    b.sort()
    g.sort()
    z = 0
    if(g[0] < b[0]):
        check(b,g,n)
    elif(g[0] > b[0]):
        check(g,b,n)
    else:
        for i in range(n):
            if(b[i] > g[i]):
                check(b[i:], g[i:], n-i)
                break
            elif(b[i] < g[i]):
                check(g[i:], b[i:], n-i)
                break
            z += 1
        if(z == n):
            print("YES")

t=int(input())
while t:
    t=t-1
    n=int(input())
    b=list(map(int,input().split()))
    g=list(map(int,input().split()))
    a=[]
    b.sort()
    g.sort()
    for i in range(n):
        a.append(b[i])
        a.append(g[i])
    c=[]
    for i in range(n):
        c.append(g[i])
        c.append(b[i])
    f,f1=0,0
    for i in range(2*n-1):
        if(a[i]>a[i+1]):
            f=1
            break
    for i in range(2*n-1):
        if(c[i]>c[i+1]):
            f1=1
            break
    if(f==0 or f1==0):
        print("YES")
    else:
        print("NO")

for _ in range(int(input())):
	N = int(input());barr = sorted(list(map(int , input().split())));garr = sorted(list(map(int , input().split())));tarr = barr + garr;ans1 = [0]*(N*2);ans2 = [0]*(N*2)
	tarr.sort();j = 0
	for i in range(N):
		ans1[j] += garr[i] 
		ans1[j + 1] += barr[i]
		ans2[j] += barr[i]
		ans2[j + 1] += garr[i]
		j += 2
	if(ans1 == tarr or ans2 == tarr): print("YES")
	else: print("NO")

for _ in range(int(input())):
    n=int(input())
    br=list(map(int,input().split()))
    gr=list(map(int,input().split()))

    br.sort()
    gr.sort()
    flag1=0
    flag2=0

    for i in range(n-1):
        if br[i]<=gr[i] and gr[i]<=br[i+1]:
            cool=1
        else:
            flag1=1

        if i==n-2:
            if gr[n-1]<br[n-1]:
                flag1=1

    for i in range(n-1):
        if gr[i]<=br[i] and br[i]<=gr[i+1]:
            cool=1
        else:
            flag2=1

        if i==n-2:
            if br[n-1]<gr[n-1]:
                flag2=1
    
    if flag1==flag2==1:
        print('NO')
    else:
        print('YES')




def f(a,b):
    if(len(b)==0):
        return True
    if(a[0]>b[0]):
        return False
    return f(b,a[1:])
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a.sort()
    b.sort()
    if(f(a,b)==True or f(b,a)==True):
        print("YES")
    else:
        print("NO")