#include #define MAX 1000010 using namespace std; int n, m, i, j, k, t; int a[MAX]; void judge(int &a) { if (a == 1) { a = 0; } else { a = 1; } } int main() { scanf("%d", &t); while (t--) { int flag = 1; int cnt = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); } for (int i = 0; i < n; i++) { if (a[i - 1] == 1) { judge(a[i - 1]); continue; } judge(a[i]); } if (a[n - 1]==0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }