import math def lcm(x, y): return x * y // math.gcd(x, y) ncases = int(input()) for caseno in range(ncases): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) def check(): if a[0] != b[0]: return False for i in range(1, len(a)): if a[i] == b[i]: continue if lcm(i + 1, 2) > n: return False a.sort(); b.sort() return a == b print("Yes" if check() else "No")