#include <bits/stdc++.h>
using namespace std;
int main(){
	int T;
	cin >> T;
	while (T--){
		int N;
		cin >> N;
		vector<int> A(N);
		for (int i = 0; i < N; i++){
			cin >> A[i];
		}
		bool ok = true;
		for (int i = 0; i < N; i++){
			if (A[i] == 0 and A[(i + 1) % N] == 0){
				ok = false;
			}
			if (A[i] == 2 and A[(i + 1) % N] == 2){
				ok = false;
			}
		}
		for (int i = 0; i < N; i++){
			if (A[i] == 0 and A[(i + 1) % N] == 1 and A[(i + 2) % N] == 0){
				ok = false;
			}
			if (A[i] == 2 and A[(i + 1) % N] == 1 and A[(i + 2) % N] == 2){
				ok = false;
			}
		}
		if (count(A.begin(), A.end(), 1) == N){
			ok = false;
		}
		if (count(A.begin(), A.end(), 0) != count(A.begin(), A.end(), 2)){
			ok = false;
		}
		if (ok){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}