import sys


def sol():
    input = sys.stdin.readline
    K = int(input())
    for _ in range(K):
        V, E = map(int, input().split())
        graph = [[] for _ in range(V + 1)]
        for _ in range(E):
            v, w = map(int, input().split())
            graph[v].append(w)
            graph[w].append(v)
        print("YES") if is_bipartite(V, graph) else print("NO")


def is_bipartite(V, graph):
    color_arr = [-1] * (V + 1)
    for i in range(1, V + 1):
        if color_arr[i] == -1:
            if not is_bipartite_util(V, graph, i, color_arr):
                return False
    return True


def is_bipartite_util(V, graph, src, color_arr):
    q = []
    q.append(src)
    color_arr[src] = 1
    while q:
        cur = q.pop(0)
        if cur in graph[cur]:
            return False
        for next in graph[cur]:
            if color_arr[next] == -1:
                color_arr[next] = 1 - color_arr[cur]
                q.append(next)
            elif color_arr[next] == color_arr[cur]:
                return False
    return True


if __name__ == "__main__":
    sol()
