#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int N=1e6+5;

struct node
{
	int sum;
	int add;
	int l;
	int r;
};

node res[N*4];
int a[N],s[N];
int x[N],y[N];

void pushup(int rt)
{
    res[rt].sum=res[rt*2].sum+res[rt*2+1].sum;
}

void pushdown(int rt)
{
	if(res[rt].add==1)
	{
		res[rt*2].sum=res[rt*2].r-res[rt*2].l+1;
		res[rt*2+1].sum=res[rt*2+1].r-res[rt*2+1].l+1;
		res[rt*2].add=res[rt*2+1].add=1;
	}
	else if(res[rt].add==-1)
	{
		res[rt*2].sum=res[rt*2+1].sum=0;
		res[rt*2].add=res[rt*2+1].add=-1;
	}

    res[rt].add=0;
}

void update(int rt,int l,int r,int num)
{
    if(l<=res[rt].l && res[rt].r<=r)
    {
        if(num==0)
        	res[rt].sum=0,res[rt].add=-1;
        else
        	res[rt].sum=res[rt].r-res[rt].l+1,res[rt].add=1;

        return;
    }

    pushdown(rt);

    int mid=(res[rt].l+res[rt].r)/2;
    if(l<=mid)
        update(rt*2,l,r,num);
    if(mid+1<=r)
        update(rt*2+1,l,r,num);

    pushup(rt);
}

void build(int rt,int l,int r)
{
    res[rt].l=l,res[rt].r=r,res[rt].add=0;
    if(l==r)
    {
    	res[rt].sum=a[l];
        return;
    }

    int mid=(l+r)/2;
    build(rt*2,l,mid);
    build(rt*2+1,mid+1,r);
    pushup(rt);
}

int quest(int rt,int l,int r)
{
	if(l<=res[rt].l && res[rt].r<=r)
		return res[rt].sum;

	pushdown(rt);
	int mid=(res[rt].l+res[rt].r)/2,ans=0;
	if(l<=mid)
		ans += quest(rt*2,l,r);
	if(mid+1<=r)
		ans += quest(rt*2+1,l,r);

	pushdown(rt);

	return ans;
}

int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		int n,m;
		cin >> n >> m;
		for(int i=1;i<=n;i++)
		{
			scanf("%1d",&s[i]);
			s[i]+=s[i-1];
		}

		for(int i=1;i<=n;i++)
			scanf("%1d",&a[i]);

		build(1,1,n);

		for(int i=1;i<=m;i++)
			scanf("%d %d",&x[i],&y[i]);

		reverse(x+1,x+m+1);
		reverse(y+1,y+m+1);

		bool yes=true; //是否成功
		for(int i=1;i<=m;i++)
		{
			int num=quest(1,x[i],y[i]);
			if(num*2==y[i]-x[i]+1)
			{
				yes=false;
				break;
			}

			if(num*2<y[i]-x[i]+1) //0更多一些
				update(1,x[i],y[i],0);
			else
				update(1,x[i],y[i],1);
		}

		if(!yes)
		{
			printf("NO\n");
			continue;
		}

		for(int i=1;i<=n;i++)
			if(s[i]!=quest(1,1,i))
			{
				yes=false;
				break;
			}

		if(!yes)
			printf("NO\n");
		else
			printf("YES\n");
	}
}