import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from copy import deepcopy as dcopy import math import sys sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def getN(): return int(sys.stdin.readline()) def getNs(): return map(int,sys.stdin.readline().split()) def getList(): return list(map(int,sys.stdin.readline().split())) def strinps(n): return [sys.stdin.readline().rstrip() for _ in range(n)] pi = 3.141592653589793 mod = 10**9+7 MOD = 998244353 INF = math.inf dx = [1,0,-1,0]; dy = [0,1,0,-1] """ Main Code """ m = 10**5 prime = [True] * (m + 1) for i in range(2, m + 1): if not prime[i]: continue for j in range(2 * i, m + 1, i): prime[j] = False for _ in [0] * getN(): n = getN() a = getList(); sa = sorted(a) b = getList(); sb = sorted(b) if(any(sa[i] != sb[i] for i in range(n)) or a[0] != b[0] or any(prime[i+1] and a[i] != b[i] for i in range(n // 2 + 1, n))): print("No") else: print("Yes")