#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define M 1000000007
#define N (1<<18)
#define P complex<long long>
#define X real()
#define Y imag()
using namespace std;
int t, n, m, z[111],par[111], sy[101], a, b, lvl[111];
bool y;
vector<int> vrk[111];
void haku(int s, int e) {
if(z[s])
return;
z[s] = 1;
for(auto u:vrk[s]) {
if(u == e)
continue;
if(z[u]) {
if(lvl[u] > lvl[s])
continue;
int k = s;
sy[k]++;
if(sy[k] == 2) {
y = true;
}
while(k != u) {
k = par[k];
sy[k]++;
if(sy[k] == 2) {
y = true;
}
}
continue;
}
par[u] = s;
lvl[u] = lvl[s]+1;
haku(u, s);
}
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin >> t;
for(int g=0; g<t; g++) {
cin >> n >> m;
y = false;
for(int i=1; i<=n; i++) {
vrk[i].clear();
sy[i] = 0;
z[i] = 0;
}
lvl[1] = 1;
for(int i=0; i<m; i++) {
cin >> a >> b;
vrk[a].push_back(b);
vrk[b].push_back(a);
}
haku(1,0);
if(y)
cout << "YES";
else
cout << "NO";
cout << "\n";
}
}