#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

using namespace std;

using ll = long long;

struct segtree {
  int n;
  vector<int> s;
  vector<int> lazy;

  segtree(int N): n(1) {
    while(n < N) n <<= 1;
    s.assign(2 * n, 0);
    lazy.assign(2 * n, -1);
  }

  void push(int k, int x, int sz) {
    s[k] = x * sz;
    if(k < n) {
      lazy[2 * k] = x;
      lazy[2 * k + 1] = x;
    }
  }

  void pop(int k, int sz) {
    if(lazy[k] >= 0) {
      push(k, lazy[k], sz);
      lazy[k] = -1;
    }
  }

  int sum(int l, int r,
          int L = 0, int R = -1, int node = 1) {
    if(node == 1) R = n;

    pop(node, R - L);
    if(l <= L && r >= R) return s[node];
    if(l >= R || r <= L) return 0;

    int mid = (L + R) / 2;
    return sum(l, r, L, mid, node * 2) + sum(l, r, mid, R, node * 2 + 1);
  }

  void update(int l, int r, int x,
              int L = 0, int R = -1, int node = 1) {
    if(node == 1) R = n;

    pop(node, R - L);
    if(l <= L && r >= R) { push(node, x, R - L); return; }
    if(l >= R || r <= L) return;

    int mid = (L + R) / 2;
    update(l, r, x, L, mid, node * 2);
    update(l, r, x, mid, R, node * 2 + 1);
    s[node] = s[2 * node] + s[2 * node + 1];
  }
};

int main() {
  cin.tie(0); ios_base::sync_with_stdio(0);

  int t; cin >> t;

  while(t--) {
    int n, m; cin >> n >> m;

    string s, f; cin >> s >> f;

    segtree st(n);

    for(int i = 0; i < n; i++) {
      st.update(i, i+1, f[i] - '0');
    }

    // 00000
    // 00000
    // 000
    // 00111

    vector<pair<int,int> > a(m);

    for(int i = 0; i < m; i++) {
      cin >> a[i].first >> a[i].second; a[i].first--;
    }

    bool good = 1;
    for(int i = m-1; i >= 0; i--) {
      int u = st.sum(a[i].first, a[i].second), v = a[i].second - a[i].first - u;

      // cout << u << " " << v << "\n";
      if(u == v) {
        good = 0;
      } else if(u < v) {
        st.update(a[i].first, a[i].second, 0);
      } else {
        st.update(a[i].first, a[i].second, 1);
      }
    }

    for(int i = 0; i < n; i++) {
      if(st.sum(i, i+1) + '0' != s[i])
        good = 0;
      // cout << st.sum(i,i+1);
    } // cout << "\n";

    cout << (good ? "YES" : "NO") << "\n";
  }

  return 0;
}
