import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); PrintWriter pw = new PrintWriter(System.out); label: for (int z = 0; z < t; z++) { int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; int[] c = new int[3]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); c[a[i]]++; } int sum = c[1] + c[2] * 2; if (sum != n || c[0] == 0 || c[2] == 0) { pw.println("No"); continue; } int start = -1; for (int i = 0; i < n; i++) { if (a[i] == 2) { start = i; break; } } boolean up = true; for (int i = start + 1; i < start + n; i++) { int x = i % n; if (up) { if (a[x] == 0) { up = false; } else if (a[x] == 1) { up = true; } else { pw.println("No"); continue label; } } else { if (a[x] == 0) { pw.println("No"); continue label; } else if (a[x] == 1) { up = false; } else { up = true; } } } if (up) { pw.println("No"); } else { pw.println("Yes"); } } pw.flush(); br.close(); } }