T = int(input()) prime = set() C = 10 ** 5 + 1 dat = [0] * C i = 2 while i < C: if dat[i] == 0: prime.add(i) for j in range(i * 2,C,i): dat[j] = 1 i += 1 for _ in range(T): N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) a = [] b = [] if A[0] != B[0]: print('No') continue flag = True for i in range(1,N): if (i+1) * 2 > N and i + 1 in prime: if A[i] != B[i]: flag = False print('No') break else: a.append(A[i]) b.append(B[i]) if flag: a.sort() b.sort() if a == b: print('Yes') else: print('No')