import sys def solve(n, a): left = [False] * n right = [False] * n idx2 = -1 for i in range(n): if a[i] == 2: idx2 = i break if idx2 == -1: return False left[idx2] = True right[idx2] = True for i in range(idx2 + 1, idx2 + n): j = i % n left[j] = not right[j-1] if a[j] == 0 and left[j] or a[j] == 2 and not left[j]: return False right[j] = (a[j] - left[j]) > 0 return True t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] print("Yes" if solve(n, a) else "No")