#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mid ((l+r)>>1)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define fors(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
const int maxn = 2e5 + 5;
char s[maxn], t[maxn];
int a[maxn], b[maxn];
int sum[maxn<<2], con[maxn<<2];
void build(int rt, int l, int r){
    con[rt] = -1;
    if(l == r){
        sum[rt] = (t[l] == '1'); return;
    }build(lson); build(rson);
    sum[rt] = sum[rt<<1] + sum[rt<<1|1];
    return;
}
void down(int rt, int l, int r){
    if(con[rt] == -1) return;

    con[rt<<1] = con[rt];
    con[rt<<1|1] = con[rt];

    sum[rt<<1] = (mid-l+1) * con[rt];
    sum[rt<<1|1] = (r-mid) * con[rt];
    con[rt] = -1;
    return;
}
void update(int rt, int l, int r, int L, int R, int x){
    if(L <= l && r <= R){
        con[rt] = x;
        sum[rt] = (r-l+1)*x; return;
    }
    down(rt, l, r);
    if(L <= mid) update(lson, L, R, x);
    if(R > mid) update(rson , L, R, x);
    sum[rt] = sum[rt<<1] + sum[rt<<1|1];
    return;
}
int qry(int rt, int l, int r, int L, int R){
    if(L <= l && r <= R) return sum[rt];
    down(rt, l, r);
    int res = 0;
    if(L <= mid) res += qry(lson , L, R);
    if(R > mid) res += qry(rson, L, R);
    return res;
}
int v[maxn];
void dfs(int rt, int l, int r){
    if(l == r){
        v[l] = sum[rt];
        return;
    }down(rt, l, r);
    dfs(lson); dfs(rson);
}
int main()
{
    int T; cin>>T;
    while(T--){
        int n, m; scanf("%d%d", &n, &m);
        scanf("%s", s+1);
        scanf("%s", t+1);
        build(1, 1, n);
        fors(i,0,m)
            scanf("%d%d", &a[i], &b[i]);
        int flag = 1;
//        cout<<qry(1,1,n,1,7)<<endl;
        for(int i = m-1; i >= 0; --i){
            int l = a[i], r = b[i];
            int res = qry(1, 1, n, l, r);
            int num = r-l+1;
//            cout<<"l:"<<l<<" r:"<<r<<endl;
//            cout<<"res:"<<res<<endl;
            if(2*res == num){
//                cout<<"i:"<<i<<endl;
                flag = 0; break;
            }else if(2*res < num) {
//                cout<<"0:"<<endl;
                update(1, 1, n, l, r, 0);
//                cout<<"qry:"<<qry(1, 1, n, 1, 7)<<endl;
            }
            else {
                update(1, 1, n, l, r, 1);
                //cout<<"1:"<<endl;
            }
        }
        //cout<<"flag:"<<flag<<endl;
        dfs(1, 1, n);
        //fors(i,1,n+1) cout<<v[i]<<" ";cout<<endl;
        fors(i,1,n+1) {
            if(s[i]-'0' != v[i]) flag = 0;
        }
        if(flag) puts("YES");
        else puts("NO");
    }
	return 0;
}
/*

1
10 6
1111111111
0110001110
1 10
5 9
7 10
1 7
3 5
6 10
*/
