#include <bits/stdc++.h>   //#include <ext/pb_ds/assoc_container.hpp>   //using namespace __gnu_pbds;   using namespace std;   typedef long long ll;   typedef long double ld;   //typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;   template<class T1, class T2>   ostream &operator <<(ostream &os, pair<T1,T2>&p);   template <class T>   ostream &operator <<(ostream &os, vector<T>&v);   template <class T>   ostream &operator <<(ostream &os, set<T>&v);   template <class T1, class T2>   ostream &operator <<(ostream &os, map<T1,T2>&v);   #ifdef APURBA   #define HERE cout<< here -  <<__LINE__<<  n ;   #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }   void err(istream_iterator<string> it)   {       cout<<endl;   }   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args)   {       cout << *it <<   =   << a <<    ;       err(++it, args...);   }   #else   #define HERE   #define debug(args...)   #endif   const int N = 5e5 +5;   const ll mod = 1e9 + 7;   typedef pair<int,int> pii;   struct info{       int zero , one;       int lazy;       info()       {           zero = 0;           one = 0;           lazy = 0;       }   };      struct segtree{       int n;       vector<info>t;          segtree(int n, string &s)       {           this->n = n;           t.resize(n*4);           build(1,0,n-1,s);       }       void Merge(info &node , info &l , info &r)       {           node.zero = l.zero + r.zero;           node.one = l.one + r.one;       }       void build(int node, int l ,int r,string &s)       {           if(l==r)           {               if(s[l]== 0 )               {                   t[node].zero = 1;               }               else{                   t[node].one = 1;               }               return;           }           int mid= (l+r)/2;           build(node*2 , l, mid,s);           build(node *2 +1 , mid+1, r,s);           Merge(t[node], t[node*2] , t[node *2+1]);       }       void push_down(int node , int  l, int r, int b, int mid , int e)       {           if(t[node].lazy==1)           {               t[l].zero = (mid-b+1);               t[l].one = 0;               t[l].lazy = 1;               t[r].zero = (e-mid);               t[r].one = 0;               t[r].lazy = 1;               t[node].lazy =0;           }           else if(t[node].lazy == 2)           {               t[l].one = (mid-b+1);               t[l].zero = 0;               t[l].lazy = 2;               t[r].one = (e-mid);               t[r].zero = 0;               t[r].lazy = 2;               t[node].lazy =0;           }       }       void update(int node, int l ,int r , int i, int j, int add)       {           if(l>j || r<i)           {               return;           }           if(l>=i && r<=j)           {               if(add==0)               {                   t[node].zero = (r-l+1);                   t[node].one = 0;                   t[node].lazy = 1;               }               else{                   t[node].one = (r-l+1);                   t[node].zero = 0;                   t[node].lazy = 2;               }               return;           }           int mid = (l+r)/2;           push_down(node, node*2, node*2+1 , l, mid, r);           update(node *2 , l ,mid , i, j, add);           update(node *2 +1 , mid+1 , r , i, j, add);           Merge(t[node] , t[node *2] , t[node*2+1]);       }       void update(int l ,int r, int add)       {           update(1,0,n-1,l,r,add);       }       info query(int node, int l, int r, int i, int j)       {           if(l>j || r<i)           {               info tmp;               return tmp;           }           if(l>=i && r<=j)           {               return t[node];           }              int mid = (l+r)/2;           push_down(node, node*2, node*2+1,l,mid,r);           info x = query(node *2 , l ,mid , i, j);           info y = query(node *2 +1 , mid+1 , r , i, j);           info ret;           Merge(ret  , x, y);           return ret;       }       pii query(int l, int r)       {           info ret = query(1,0,n-1,l,r);           return make_pair(ret.zero , ret.one);       }       void show()       {           for(int i=0;i<n;i++)           {               pii tmp = query(i,i);               cout<<tmp<<   ;           }           cout<<endl;       }   };         void TEST_CASES(int cas)   {       int n,q;       string s,t;       cin>>n>>q>>s>>t;       vector<pii>a(q);       for(int i=0;i<q;i++)       {           int l,r;           cin>>l>>r;           l--;           r--;           a[i] = {l,r};       }       segtree seg(n,t);       //seg.show();       for(int i=q-1;i>=0;i--)       {           int l = a[i].first , r = a[i].second;           int sz = (r-l+1);           pii koto = seg.query(l,r);           //debug(i,koto);           if(koto.first*2<sz)           {               //HERE;               seg.update(l,r,1);           }           else if(koto.second*2<sz)           {               seg.update(l,r,0);           }           else{               cout<< NO n ;               return;           }           //seg.show();       }       for(int i=0;i<n;i++)       {           int eta = s[i]- 0 ;           pii bal = seg.query(i,i);           if(eta==0 && bal.second==1)           {               cout<< NO n ;               return;           }           else if(eta==1 && bal.first==1)           {               cout<< NO n ;               return;           }       }       cout<< YES n ;         }               /*      */      int32_t main()   {   #ifndef APURBA       ios_base::sync_with_stdio(false);       cin.tie(nullptr);   #endif       //freopen( input.txt , r ,stdin);       //freopen( out1.txt , w ,stdout);       int t=1,cas=0;       cin>>t;       while(t--)       {           TEST_CASES(++cas);       }       return 0;   }            template<class T1, class T2>   ostream &operator <<(ostream &os, pair<T1,T2>&p)   {       os<< { <<p.first<< ,  <<p.second<< }  ;       return os;   }   template <class T>   ostream &operator <<(ostream &os, vector<T>&v)   {       os<< [  ;       for(int i=0; i<v.size(); i++)       {           os<<v[i]<<    ;       }       os<<  ] ;       return os;   }      template <class T>   ostream &operator <<(ostream &os, set<T>&v)   {       os<< [  ;       for(T i:v)       {           os<<i<<   ;       }       os<<  ] ;       return os;   }   template <class T1, class T2>   ostream &operator <<(ostream &os, map<T1,T2>&v)   {       for(auto i:v)       {           os<< Key :  <<i.first<<  , Value :  <<i.second<<endl;       }       return os;   }