import sys input = sys.stdin.readline for _ in [0] * int(input()): n = int(input()) a = list(map(int, input().split())) graph = [set([]) for _ in [0] * n] stk = list((x, -1) for x in range(n) if(a[x] == 2)) st = set(stk) while(stk): v, lv = stk.pop() pv, nv = (v - 1) % n, (v + 1) % n if(a[v] == 2): graph[v].add(pv) graph[v].add(nv) if(pv not in st): st.add(pv) stk.append((pv, v)) if(nv not in st): st.add(nv) stk.append((nv, v)) elif(a[v] == 1): if(pv != lv): graph[v].add(pv) if(pv not in st): st.add(pv) stk.append((pv, v)) else: graph[v].add(nv) if(nv not in st): st.add(nv) stk.append((nv, v)) for v, c in enumerate(a): if(len(graph[v]) == c): continue print("No") break else: print("Yes")