/* _ _ | (_) _ __ __ _ _ __ __ _ ___ ___ ___ __| |_ _ __ __ _ | '_ \ / _` | '__/ _` / __|/ __/ _ \ / _` | | '_ \ / _` | | |_) | (_| | | | (_| \__ \ (_| (_) | (_| | | | | | (_| | | .__/ \__,_|_| \__,_|___/\___\___/ \__,_|_|_| |_|\__, | | | __/ | |_| |___/ */ import java.lang.*; import java.math.*; import java.io.*; import java.util.*; public class Main{ public static Reader br; public static PrintWriter ot; public static int[] take_arr(int n) throws IOException{ int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = br.nextInt(); return a; } public static List take_list(int n) throws IOException{ List a = new ArrayList<>(); for(int i = 0; i < n; i++) a.add(br.nextInt()); return a; } public static void main (String[] args) throws IOException { br = new Reader(); ot = new PrintWriter(System.out); int t = br.nextInt(); pre(); while(t-- > 0){ int n = br.nextInt(); // int m = br.nextInt(); // int k = br.nextInt(); solve(n); } ot.close(); br.close(); } static void solve() throws IOException{ } static void solve(int n) throws IOException{ int a[] = take_arr(n); List list = new ArrayList<>(); int i = 0; while(i < n){ int j = i; while(j < n && a[i] == a[j]) j++; list.add(a[i]); i = j; } if(list.size() % 2 == 1){ ot.println("No"); return; } boolean ans = false, temp = true; int ele = 1; for(int x : list){ if(x != ele){ temp = false; break; } ele ^= 1; } ans |= temp; temp = true; ele = 0; for(int x : list){ if(x != ele){ temp = false; break; } ele ^= 1; } ans |= temp; if(ans) ot.println("Yes"); else ot.println("No"); } static void solve(int n, int m) throws IOException{ } static List> adj; static long mod = (long)(1e9 + 7); static void pre() throws IOException { } // Template Functions static long exp(long a, long b, long mod){ long ans = 1; while(b > 0){ if((b & 1) == 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[(int)(1e5 + 1)]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } }