#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> ii;

string s,f,rc;
int ar[2000000];
bool tp[2000000];
int la[2000000];

int con(int r,int l1, int l2){
	tp[r]=false;
	if(l1==l2){
		if(f[l1]=='1')ar[r]=1;
		else ar[r]=0;
		//cout<<r<<' '<<l1<<' '<<ar[r]<<endl;
		return ar[r];
	}
	int m = (l1+l2)/2;
	return ar[r] = con(r<<1, l1,m)+ con((r<<1)+1, m+1,l2);
}

int up(int r, int l1, int l2, int q1, int q2, int va){
	if(q2<l1||q1>l2)return 0;
	if(q1<=l1&&q2>=l2){
		tp[r]=true;
		la[r]=va;
		if(va)ar[r]=l2-l1+1;
		else ar[r]=0;
		return ar[r];
	}
	int m = (l1+l2)/2;
	if(tp[r]){
		tp[r]=false;
		up(r<<1, l1,m,l1,m,la[r]);
		up((r<<1)+1, m+1,l2,m+1,l2,la[r]);
	}
	up(r<<1, l1,m,q1,q2,va);
	up((r<<1)+1, m+1,l2,q1,q2,va);
	return ar[r]=ar[r<<1]+ar[(r<<1)+1];
}

int qu(int r,int l1,int l2,int q1, int q2){
	if(q2<l1||q1>l2)return 0;
	if(q1<=l1&&q2>=l2)return ar[r];
	int m = (l1+l2)/2;
	if(tp[r]){
		tp[r]=false;
		up(r<<1, l1,m,l1,m,la[r]);
		up((r<<1)+1, m+1,l2,m+1,l2,la[r]);
	}
	return qu(r<<1,l1,m,q1,q2)+qu((r<<1)+1,m+1,l2,q1,q2);
}

int rec(int r,int l1, int l2){
	if(l1==l2){
		if(ar[r])rc[l1]='1';
		else rc[l1]='0';
		//cout<<r<<' '<<l1<<' '<<ar[r]<<endl;
		return 0;
	}
	int m = (l1+l2)/2;
	if(tp[r]){
		tp[r]=false;
		up(r<<1, l1,m,l1,m,la[r]);
		up((r<<1)+1, m+1,l2,m+1,l2,la[r]);
	}
	return rec(r<<1, l1,m)+ rec((r<<1)+1, m+1,l2);
}

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--){
		int n,q;
		cin>>n>>q;
		cin>>s>>f;
		con(1,0,n-1);
		//cout<<"te\n";
		rc=s;
		bool va=true;
		int en[q][2];
		for(int i=0;i<q;i++)cin>>en[i][0]>>en[i][1];
		for(int i=q-1;i>=0;i--){
			int l,r;
			l=en[i][0];
			r=en[i][1];
			if(va){
				l--;r--;
				int tn = r-l+1;
				int n1 = qu(1,0,n-1,l,r);
				int n0 = tn-n1;
				if(n1<n0)up(1,0,n-1,l,r,0);
				else if(n0<n1)up(1,0,n-1,l,r,1);
				else va=false;
			}
		}
		rec(1,0,n-1);
		if(va&&s.compare(rc)==0)cout<<"YES\n";
		else cout<<"NO\n";
	}
	
	
	return 0;
}