#include <bits/stdc++.h>
/*
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
— Rick Osborne
*/
using namespace std;
typedef pair <int,int> PII;
typedef vector <int> VI;
typedef vector < PII > VPII;
int main()
{
int tc;
scanf("%d",&tc);
while (tc--)
{
int m, n;
scanf("%d %d",&m, &n);
VPII segm;
for(int i=0;i<n;i++)
{
int st, en;
scanf("%d %d",&st, &en);
if(st<=en)
{
segm.push_back(make_pair(st,en));
segm.push_back(make_pair(st+m,en+m));
}
else
segm.push_back(make_pair(st,en+m));
}
if(n>m)
{
puts("NO");
continue;
}
sort(segm.begin(),segm.end());
int T=0;
int i=0;
set < PII > que;
bool ok = true;
while(true)
{
if(que.empty())
{
if(i==segm.size())
break;
else
T = segm[i].first;
}
while(i<segm.size() && segm[i].first==T)
{
que.insert(make_pair(segm[i].second,i));
i++;
}
int ind = que.begin()->second;
que.erase(que.begin());
if(!(T>=segm[ind].first && T<=segm[ind].second))
{
ok = false;
break;
}
T++;
}
puts(ok?"YES":"NO");
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8qIAogQWx3YXlzIGNvZGUgYXMgaWYgdGhlIGd1eSB3aG8gZW5kcyB1cCBtYWludGFpbmluZyB5b3VyIGNvZGUgd2lsbCBiZSBhIHZpb2xlbnQgcHN5Y2hvcGF0aCB3aG8ga25vd3Mgd2hlcmUgeW91IGxpdmUuCiDigJQgUmljayBPc2Jvcm5lCiAgKi8KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBwYWlyIDxpbnQsaW50PiBQSUk7CnR5cGVkZWYgdmVjdG9yIDxpbnQ+IFZJOyAKdHlwZWRlZiB2ZWN0b3IgPCBQSUkgPiBWUElJOwppbnQgbWFpbigpCnsKICAgIGludCB0YzsKICAgIHNjYW5mKCIlZCIsJnRjKTsKCQl3aGlsZSAodGMtLSkKICAgIHsKICAgICAgICBpbnQgbSwgbjsKICAgICAgICBzY2FuZigiJWQgJWQiLCZtLCAmbik7CgkJCQlWUElJIHNlZ207CiAgICAgICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgICB7CiAgICAgICAgICAgIGludCBzdCwgZW47CiAgICAgICAgICAgIHNjYW5mKCIlZCAlZCIsJnN0LCAmZW4pOwogICAgICAgICAgICBpZihzdDw9ZW4pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNlZ20ucHVzaF9iYWNrKG1ha2VfcGFpcihzdCxlbikpOwogICAgICAgICAgICAgICAgc2VnbS5wdXNoX2JhY2sobWFrZV9wYWlyKHN0K20sZW4rbSkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHNlZ20ucHVzaF9iYWNrKG1ha2VfcGFpcihzdCxlbittKSk7CiAgICAgICAgfQoJCQkJaWYobj5tKQogICAgICAgIHsKICAgICAgICAgICAgcHV0cygiTk8iKTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIHNvcnQoc2VnbS5iZWdpbigpLHNlZ20uZW5kKCkpOwogICAgICAgIAoJCQkJaW50IFQ9MDsKICAgICAgICBpbnQgaT0wOwogICAgICAgIHNldCA8IFBJSSA+IHF1ZTsKICAgICAgICBib29sIG9rID0gdHJ1ZTsKICAgICAgICB3aGlsZSh0cnVlKQogICAgICAgIHsKICAgICAgICAgICAgaWYocXVlLmVtcHR5KCkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKGk9PXNlZ20uc2l6ZSgpKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIFQgPSBzZWdtW2ldLmZpcnN0OwogICAgICAgICAgICB9CiAgICAgICAgCgkJCQkJCXdoaWxlKGk8c2VnbS5zaXplKCkgJiYgc2VnbVtpXS5maXJzdD09VCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcXVlLmluc2VydChtYWtlX3BhaXIoc2VnbVtpXS5zZWNvbmQsaSkpOwogICAgICAgICAgICAgICAgaSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIAoJCQkJCQlpbnQgaW5kID0gcXVlLmJlZ2luKCktPnNlY29uZDsKICAgICAgICAgICAgcXVlLmVyYXNlKHF1ZS5iZWdpbigpKTsKICAgICAgICAgICAgCgkJCQkJCWlmKCEoVD49c2VnbVtpbmRdLmZpcnN0ICYmIFQ8PXNlZ21baW5kXS5zZWNvbmQpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBvayA9IGZhbHNlOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgVCsrOwogICAgICAgIH0KICAgICAgICBwdXRzKG9rPyJZRVMiOiJOTyIpOwogICAgfQp9