t=int(input()) for _ in range(t): _=input() a=''.join(input().split()) res='Yes' if a[0]==a[-1]: aa=['11','00'][int(a[0])] if aa not in a: b=[] p=3 for ai in a: if ai!=p: b.append(ai) p=b[-1] if len(b)<=8: res='No' print(res)