#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> adj[1000];
int prevv[1000];
bool visited[1000];
bool inCycle[1000];
bool found = false;
set<int> setti[1000];
void dfs(int v, int e) {
if (found) return;
visited[v] = true;
prevv[v] = e;
for (int next : adj[v]) {
if (next == e) continue;
if (!visited[next]) {
dfs(next,v);
} else {
if (setti[v].find(next) != setti[v].end()) continue;
if (inCycle[next]) {
found = true;
return;
}
setti[next].insert(v);
inCycle[next] = true;
int x = v;
while(x != next) {
if (inCycle[x]) {
found = true;
return;
}
inCycle[x] = true;
x = prevv[x];
}
}
}
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n,m;
cin >> n >> m;
for (int j = 1; j <= n; j++) {
adj[j].clear();
setti[j].clear();
visited[j] = false;
inCycle[j] = false;
}
found = false;
for (int j = 0; j < m; j++) {
int a,b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int node = 1; node <= n; node++) {
if (!visited[node]) {
dfs(node,0);
}
}
if (found) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}