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

int N,K;
vector<int> tree;
vector<int> changes; //-1 if no change, 0 or 1 otherwise

void propagate(int i, int k){ //i = position, k = layer
    if(changes[i] != -1){
        tree[i] = changes[i]*(1 << k);
        if(i < N) changes[2*i] = changes[2*i+1] = changes[i];
        changes[i] = -1;
    }
}

void update(int i, int k){
    if(i < N){
        propagate(2*i,k); propagate(2*i+1,k);
        tree[i] = tree[2*i] + tree[2*i+1];
    }
}

int ask0(int l, int r, int i, int k){ //i = position, k = layer
    propagate(i,k);
    if(l <= (i << k) && ((i+1) << k)-1 <= r) return tree[i];
    else if(((i+1) << k)-1 < l || r < (i << k)) return 0;
    else{
        int ans = ask0(l,r,2*i,k-1) + ask0(l,r,2*i+1,k-1);
        update(i,k); return ans;
    }
}

int ask(int l, int r){
    return ask0(l+N,r+N,1,K);
}

void change0(int l, int r, int c, int i, int k){
    propagate(i,k);
    if(l <= (i << k) && ((i+1) << k)-1 <= r){
        changes[i] = c; propagate(i,k);
    }
    else if(((i+1) << k)-1 < l || r < (i << k)) return;
    else{
        change0(l,r,c,2*i,k-1); change0(l,r,c,2*i+1,k-1); update(i,k);
    }
}

bool change(int l, int r){ //false if invalid
    int a = ask(l,r);
    if(2*a == r-l+1) return false;
    int c = (2*a > r-l+1);
    change0(l+N,r+N,c,1,K);
    return true;
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while(t--){
        int n,q; cin >> n >> q;
        string s,f; cin >> s >> f;
        vector<tuple<int,int>> queries(q);
        for(int i = q-1; i >= 0; i --){
            int l,r; cin >> l >> r;
            queries[i] = make_tuple(l-1,r-1);
        }
        N = 1; K = 0;
        while(N < n){
            N <<= 1; K ++;
        }
        vector<int>(2*N).swap(tree);
        vector<int>(2*N,-1).swap(changes);
        for(int i = 0; i < n; i ++) tree[i+N] = (f[i] == '1');
        for(int i = N-1; i > 0; i --) tree[i] = tree[2*i] + tree[2*i+1];
        bool okay = true;
        for(auto [l,r] : queries){
            if(!change(l,r)){
                okay = false; break;
            }
        }
        if(!okay) cout << "NO\n";
        else{
            //propagate all
            for(int k = 0; k <= K; k ++){
                for(int i = (1 << k); i < (1 << (k+1)); i ++) propagate(i,K-k);
            }
            for(int i = 0; i < n; i ++){
                if(tree[i+N] != (s[i]-'0')){
                    okay = false; break;
                }
            }
            cout << (okay ? "YES\n" : "NO\n");
        }
    }
}