# 全部決まっとるやんけ t = int(input()) def is_shitoshito(arr): if len(arr) != 5: return False x1, x2, x3, x4, x5 = arr if x1 == x3 and x2 == x4 == x5 and x1 != x2: return True return False def solve(): n = int(input()) a = list(map(int, input().split())) if all(is_shitoshito(a[5*i:5*i+5]) for i in range(n)): print("Yes") else: print("No") for _ in range(t): solve()