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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        string a,b;
        cin>>a;
        cin>>b;

        int i=n-1;
        int j=m-1;

        bool flag=true;

        while(j>=1){
            if(a[i]!=b[j]){
            flag=false;
            break;
            }
            i--;
            j--;
        }

        if(flag==false){
            cout<<"no"<<endl;
        }else{
            for(int l=0;l<n-m+1;l++){
                if(b[0]==a[l]){
                    flag=true;
                    break;
                }
                else{
                    flag=false;
                }
            }
            if(flag){
                cout<<"yes"<<endl;
            }else{
                cout<<"no"<<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: