#include <iostream>
#include <vector>
using namespace std;
vector<int> v[101];
int t[101];
bool o[101];
void dfs(int x, int a, vector<int> p, int l) {
if (o[x]) {
if (x == a) {
for (int i = 0; i < p.size(); i++) {
t[p[i]]++;
}
}
return;
}
o[x] = 1;
p.push_back(x);
for (auto u : v[x]) {
if (u == l) continue;
dfs(u, a, p, x);
}
o[x] = 0;
}
int main() {
int w;
cin >> w;
while (w--) {
int n, m, a, b;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
if (v[i].size() > 2) {
for(int i=0;i<101;i++) o[i] = 0;
dfs(i, i, {}, 0);
}
}
for (int i = 1; i <= n; i++) {
if (t[i] > 2) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
}