def deletethosefucks(j):
if j in graph.keys() and (len(graph[j]) <= 1 or len(graph[j]) == 2 and graph[j].__contains__(j)):
nodestochecknext = graph[j]
del graph[j]
for node in nodestochecknext:
if node in graph.keys():
graph[node].remove(j)
deletethosefucks(node)
cases = int(input())
for i in range(cases):
nodes, edges = list(map(int, input().split()))
graph = {}
for j in range(nodes):
graph[j + 1] = []
for _ in range(edges):
a, b = list(map(int, input().split()))
graph[a].append(b)
if b != a:
graph[b].append(a)
somelinse = []
for j in graph.keys():
if len(graph[j]) <= 1 or len(graph[j]) == 2 and graph[j].__contains__(j):
somelinse.append(j)
for j in somelinse:
deletethosefucks(j)
for j in somelinse:
deletethosefucks(j)
for j in somelinse:
deletethosefucks(j)
for j in somelinse:
deletethosefucks(j)
for j in graph.keys():
if len(graph[j]) > 2:
print("YES")
break
else:
print("NO")
# for arr in graph.values():
# print(arr)
# if (len(arr) > 2):
# a += 1
# if a > 1:
# print("YES")
# else:
# print("NO")