from sys import stdin q, *indata = map(int, stdin.read().split()) offset = 0 for _ in range(q): n = indata[offset] offset += 1 a = [] b = [] for i in range(n): a.append(indata[offset+i]) b.append(indata[offset+n+i]) offset += n*2 lastind = 0 lastval = b[0] check = True for i in range(1,n): if lastval != b[i]: maxval = 0 for j in range(lastind,i): maxval = max(maxval,a[j]) if maxval != lastval: check = False break else: lastval = b[i] lastind = i if check: maxval = 0 for j in range(lastind,n): maxval = max(maxval,a[j]) if maxval != lastval: check = False if check: print("Yes") else: print("No")