import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd def sol(): n = int(input()) a = list(map(int,input().split())) a = a+a ok = 1 for i in range(2): lr = [[]] for i in range(2*n): if a[i] == 0: lr.append([]) else: lr[-1].append(a[i]) if len(lr) == 1: ok = 0 for i in range(len(lr)): if lr[i].count(2) >= 2: ok = 0 for i in range(2*n): if a[i] == 0: a[i] = 2 if a[i] == 2: a[i] = 0 print('Yes') if ok else print('No') return T = int(input()) for i in range(T): sol()