# your code goes here
t=int(input())
for i in range(t):
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
for j in range(n):
if a[j]<b[j]:
a[j],b[j]=b[j],a[j]
if a[n-1]==max(a) and b[n-1] == max(b):
print("Yes")
else:
print("No")
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCgoKdD1pbnQoaW5wdXQoKSkKCmZvciBpIGluIHJhbmdlKHQpOgoJCgkKICAgIG49aW50KGlucHV0KCkpCiAgICBhPWxpc3QobWFwKGludCwgaW5wdXQoKS5zcGxpdCgpKSkKICAgIGI9bGlzdChtYXAoaW50LCBpbnB1dCgpLnNwbGl0KCkpKQogICAgCiAgICAKICAgIAogICAgCiAgICAKIAogICAgZm9yIGogaW4gcmFuZ2Uobik6CiAgICAgICAgaWYgYVtqXTxiW2pdOiAKICAgICAgICAJCiAgICAgICAgCQogICAgICAgIAkKICAgICAgICAJCiAgICAgICAgCQogICAgICAgIAkKICAgICAgICAJCiAgICAgICAgICAgIGFbal0sYltqXT1iW2pdLGFbal0KICAgICAgICAgICAgCiAgICAgICAgICAgIAogICAgICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgICAgIAogICAgICAgICAgICAKICAgIGlmIGFbbi0xXT09bWF4KGEpIGFuZCBiW24tMV0gPT0gbWF4KGIpOgogICAgICAgIHByaW50KCJZZXMiKQogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgZWxzZTogCiAgICAgICAgcHJpbnQoIk5vIikKCg==
NwozCjcgOSA3CjcgNiA5CjQKMTAgMTAgMTUgMTUKMTAgMTYgMTUgMTUKMgoxMDAgOTkKOTkgMTAwCjEKMQoxCjkKMSAyIDMgNCA1IDYgNyA4IDkKOSA5IDkgOSA5IDkgNiA2IDYKNwoxIDEgMiAyIDEgMSAyCjEgMiAxIDIgMSAyIDEKMgozMCA0CjUgMzAK
7
3
7 9 7
7 6 9
4
10 10 15 15
10 16 15 15
2
100 99
99 100
1
1
1
9
1 2 3 4 5 6 7 8 9
9 9 9 9 9 9 6 6 6
7
1 1 2 2 1 1 2
1 2 1 2 1 2 1
2
30 4
5 30