因为可以旋转,所以可将1、2视为一种,将3、4、5、6视为一种

我们直接模拟,一列一列的走,12直接走去下一列

走到3456的时候需要判断一下这一列的另一个是不是也是3456,如果不是直接no

然后走到最后一列判断一下,是不是在第二列

#include<bits\stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int len;
        string s[2];
        cin>>len;
        cin>>s[0];
        cin>>s[1];
        int k=0; //k表示当前处理的那个在第几行,第1行是0,第二行是1
		//开始从左上角出发,所以将k初始值设为0 
        bool ok=true; //是否满足 
        for(int i=0;i<len;i++){
           if(s[k][i]=='1'||s[k][i]=='2') continue;
           else{ //要是当前那一行不是1或2就需要切换到另一行 
               if(s[1-k][i]=='1'||s[1-k][i]=='2'){ //1-k就是另一行(k=0,1-k=1;k=1,1-k=0) 
                   ok=false; //开始就堵住了直接不行 
                   break;
               }
               else k=1-k; //同上,切到另一行 
		   }          
        }
        if(ok){ 
            if(k==1)cout<<"YES"<<endl; //如果最后那个在第二行,说明可以 
            else cout<<"NO"<<endl; //不在第二行也不行 
        }
        else cout<<"NO"<<endl;
    }
    return 0;
}