#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
void isok(vector<vector<int>> & adj, vector<bool> & seen, int node, int start, int & seenstart, int prevnode) {
seen[node] = true;
for (auto nb : adj[node]) {
if (nb == start && start != prevnode) {
seenstart++;
}
if (!seen[nb]) {
isok(adj, seen, nb, start, seenstart, node);
}
}
return;
}
int main() {
int tests; cin>>tests;
while (tests--) {
int n,edges; cin>>n>>edges;
vector<vector<int>> adj(n);
while(edges--) {
int start, end; cin>>start>>end;
start--;end--;
adj[start].emplace_back(end);
adj[end].emplace_back(start);
}
bool isbi = false;
for (int node = 0; node < n; node++) {
vector<bool> seen(n);
int seenstart = 0;
isok(adj, seen, node, node, seenstart, -1);
if (seenstart >= 2) {
isbi = true;
break;
}
}
if (isbi) {
cout << "YES" << "\n";
} else {
cout << "NO" << "\n";
}
}
}