#include <cstdio>
struct SegmentT{
    int l,r;
    int v[2]; // last 0, last 1
    int tag; // 1 for org, 2 for all 0, 3 for all 1, 4 for both
    int c;
};
SegmentT t[800005];
int s[200005], f[200005];
int x[200005], y[200005];

void build(int p,int l,int r){
    t[p].l = l, t[p].r = r;
    t[p].c = 0; t[p].tag = 1;
    if(l==r){
        int u = f[l];
        t[p].v[u] = 0, t[p].v[!u] = 1;
    }
    else{
        int m = (l+r)/2;
        build(2*p,l,m);
        build(2*p+1,m+1,r);
        t[p].v[0] = t[2*p].v[0]+t[2*p+1].v[0];
        t[p].v[1] = t[2*p].v[1]+t[2*p+1].v[1];
    }
}

void spread(int p){
    if(t[p].c!=0){
        int c = t[p].c;
        t[p].c = 0;
        t[2*p].c = t[2*p+1].c = c;
        int u = c%2;
        t[2*p].v[u] = t[2*p+1].v[u] = 0;
        if(c!=4){
            t[2*p].v[!u] = t[2*p].r-t[2*p].l+1;
            t[2*p+1].v[!u] = t[2*p+1].r-t[2*p+1].l+1;
        }
        else{
            t[2*p].v[!u] = 0;
            t[2*p+1].v[!u] = 0;
        }
    }
}

void change(int p,int l,int r,int tag){
    if(l<=t[p].l && r>=t[p].r){
        t[p].c = tag;
        if(tag==2){
            t[p].v[0] = 0;
            t[p].v[1] = t[p].r-t[p].l+1;
        }
        else if(tag==3){
            t[p].v[1] = 0;
            t[p].v[0] = t[p].r-t[p].l+1;
        }
        else{
            t[p].v[0] = t[p].v[1] = 0;
        }
    }
    else{
        spread(p);
        int m = (t[p].l+t[p].r)/2;
        if(l<=m) change(2*p,l,r,tag);
        if(r>=m+1) change(2*p+1,l,r,tag);
        t[p].v[0] = t[2*p].v[0]+t[2*p+1].v[0];
        t[p].v[1] = t[2*p].v[1]+t[2*p+1].v[1];
    }
}

int ask(int p,int l,int r,int tag){
    if(l<=t[p].l && r>=t[p].r) return t[p].v[tag];
    else{
        spread(p);
        int res = 0;
        int m = (t[p].l+t[p].r)/2;
        if(l<=m) res += ask(2*p,l,r,tag);
        if(r>=m+1) res += ask(2*p+1,l,r,tag);
        return res;
    }
}

int getTag(int p,int x){
    if(t[p].l==t[p].r) return t[p].c;
    else{
        spread(p);
        int m = (t[p].l+t[p].r)/2;
        if(x<=m) return getTag(2*p,x);
        else return getTag(2*p+1,x);
    }
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i = 1; i <= n; i++){ 
        scanf("%1d",&s[i]);
    }
    for(int i = 1; i <= n; i++) scanf("%1d",&f[i]);
    for(int i = 1; i <= q; i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    build(1,1,n);
    int ok = 1;
    for(int i = q; i >= 1; i--){
        int l = x[i], r = y[i];
        int s0 = ask(1,l,r,0), s1 = ask(1,l,r,1);
        int len = r-l+1;
        int tag = -1;
        if(s0*2 >= len && s1*2 >= len){
            ok = 0;
            break;
        }
        else if(s0*2 < len && s1*2 < len) tag = 4;
        else if(s1*2 < len) tag = 3;
        else tag = 2;
        change(1,l,r,tag);
        // printf("s0 = %d, s1 = %d\n",s0,s1);
        // printf("i = %d, l = %d, r = %d, tag = %d\n",i,l,r,tag);
    }
    if(ok){
        for(int i = 1; i <= n; i++){
            int tt = getTag(1,i);
            if(tt==2){
                if(s[i]!=0) ok = 0;
            }
            else if(tt==3){
                if(s[i]!=1) ok = 0;
            }
            else{
                if(s[i]!=f[i]) ok = 0;
            }
        }
    }
    if(ok) printf("YES\n");
    else printf("NO\n");
}
    return 0;
}
