#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pri;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int t;
    cin >> t;
    while(t--) {
        int n, m;
        cin >> n >> m;
        map<int, int> mp;
        for(int i = 1; i <= m; i++) {
            int a, b;
            cin >> a >> b;
            mp[b] |= (1 << (a - 1));
        }

        bool isLast = false;
        int num = 0;
        bool flag = true;
        for(auto[a, b] : mp) {
            if (b != 3 && isLast) {
                int tmp = (a + b) % 2;
                if(tmp == num)  {
                    flag = false;
                    break;
                } else {
                    isLast = false;
                }
            } else if(b == 3 && isLast) {
                flag = false;
                break;
            } else if(b != 3){
                num = (a + b) % 2;
                isLast = true;
            }
        }
        if(isLast) flag = false;
        if(flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}