#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1010
vector<int> v[N];
int t[N], h[N];
bool f = 0;
bool haku(int s, int hh){
h[s] = hh;
int k = t[s];
for(int i : v[s]){
if(h[i] == 0){
k += haku(i, hh+1);
}else if(h[i] < hh-1) {
t[i] -= 1;
++k;
}
}
if(k > 1) f = 1;
return k;
}
int main() {
int T; cin >> T;
while(T--){
int n, m; cin >> n >> m;
for(int i=1; i<=n; ++i) {
v[i].clear();
h[i] = t[i] = 0;
}
for(int i=0; i<m; ++i){
int a, b; cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
f=0;
for(int i=1; i<=n; ++i) if(!h[i]) haku(i, 1);
if(f) cout << "YES\n";
else cout << "NO\n";
}
}