#include <bits/stdc++.h>

using namespace std;

bool helmper(string s,int n){
    bool ans=false;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            ans=true;
            break;
        }
    }
    return ans;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n1,n2;
        cin>>n1>>n2;
        string s1,s2;
        cin>>s1>>s2;
        // int n1=s1.size();
        // int n2=s2.size();
        string ans="YES";
        bool f1=helmper(s1,n1);
        bool f2=helmper(s2,n2);
        if(f1 &&f2 ) ans="NO";
        else if(f1 || f2){
            if(s1[n1-1]==s2[n2-1]) ans="NO";
        }
        cout<<ans<<endl;
        // if(f1) cout<<"YES"<<endl;
        // if(f2) cout<<"YES"<<endl;
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: