#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int test; cin >> test;
    while(test--){
        int N; cin >> N;
        vector<int> A(N);
        for(auto &a : A) cin >> a;

        bool zero = false,two = false;
        for(int i=0; i<N; i++){
            if(A.at(i) == 0) zero = true;
            if(A.at(i) == 2) two = true;
        }
        if(!zero || !two){cout << "No" << endl; continue;}

        int before = -1;
        bool yes = true;
        for(int i=0; i<2*N; i++){
            int pos = i%N;
            if(A.at(pos) == 1) continue;
            if(A.at(pos) == 0 && before == 0) yes = false;
            if(A.at(pos) == 2 && before == 2) yes = false;

            before = A.at(pos);
        }
        if(yes) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}