#include <cstdio>
#include <cstring>
#include <algorithm>
#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((l + r) >> 1)
using namespace std;

const int MAXN = 2e5 + 5;

struct Node {
	int tag, cnt;
} tr[MAXN << 2];

int T, n, q, a[MAXN], b[MAXN];
char s[MAXN], t[MAXN];

void build(int x, int l, int r) {
	if (l == r) {
		tr[x].cnt = (int)(s[l] == '1');
		tr[x].tag = -1;
		return;
	}
	build(ls, l, mid), build(rs, mid + 1, r);
	tr[x] = (Node){-1, tr[ls].cnt + tr[rs].cnt};
}

void cover(int x, int l, int r, int delta) {
	tr[x].tag = delta;
	tr[x].cnt = delta ? r - l + 1 : 0;
}

void pushdown(int x, int l, int r) {
	if (tr[x].tag == -1) return;
	cover(ls, l, mid, tr[x].tag), cover(rs, mid + 1, r, tr[x].tag);
	tr[x].tag = -1;
}

int qry(int x, int l, int r, int p, int q) {
	if (l == p && r == q) return tr[x].cnt;
	pushdown(x, l, r);
	if (q <= mid) return qry(ls, l, mid, p, q);
	if (p > mid) return qry(rs, mid + 1, r, p, q);
	return qry(ls, l, mid, p, mid) + qry(rs, mid + 1, r, mid + 1, q);
}

void mdf(int x, int l, int r, int p, int q, int delta) {
	if (l == p && r == q) {
		cover(x, l, r, delta);
		return;
	}
	pushdown(x, l, r);
	if (q <= mid) mdf(ls, l, mid, p, q, delta);
	else if (p > mid) mdf(rs, mid + 1, r, p, q, delta);
	else mdf(ls, l, mid, p, mid, delta), mdf(rs, mid + 1, r, mid + 1, q, delta);
	tr[x].cnt = tr[ls].cnt + tr[rs].cnt;
}

bool check(int x, int l, int r) {
	if (l == r) return tr[x].cnt == (int)(t[l] == '1');
	pushdown(x, l, r);
	return check(ls, l, mid) && check(rs, mid + 1, r);
}

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &q);
		scanf("%s%s", t + 1, s + 1);
		for (int i = 1; i <= q; i++)
			scanf("%d%d", &a[i], &b[i]);

		build(1, 1, n);

		bool ans = true;
		for (; q && ans; q--) {
			int len = b[q] - a[q] + 1;
			int cnt = qry(1, 1, n, a[q], b[q]);
			if (cnt < (len + 1) / 2) mdf(1, 1, n, a[q], b[q], 0);
			else if (len - cnt < (len + 1) / 2) mdf(1, 1, n, a[q], b[q], 1);
			else ans = false;
		}

		if (ans) ans &= check(1, 1, n);
		printf(ans ? "YES\n" : "NO\n");
	}
	return 0;
}