#include <bits/stdc++.h>
using namespace std;
int t;
int n, m;
vector<int> rt[101];
int u[101];
int f(int c, int p){
if (u[c]){
++u[c];
return 1;
}
u[c]=1;
int cc=0;
for (auto w:rt[c]){
if (w==p) continue;
int a=f(w, c);
if (a==-1) return -1;
cc+=a;
}
if (cc>2) return -1;
cc-=2*(u[c]-1);
return cc;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> t;
for (int ii=0;ii<t;++ii){
cin >> n >> m;
for (int i=1;i<=n;++i) rt[i].clear();
for (int i=1;i<=n;++i) u[i]=0;
for (int i=0;i<m;++i){
int a, b;
cin >> a >> b;
rt[a].push_back(b);
rt[b].push_back(a);
}
bool h=0;
for (int i=1;i<=n;++i){
if (!u[i]) {
int w=f(i,i);
if (w==-1) h=1;
}
}
cout << (h?"YES\n":"NO\n");
}
}