import sys
input = sys.stdin.readline

dsu = []

def find(x):
    global dsu
    while dsu[x] >= 0:
        x = dsu[x]
    return x

def join(a, b):
    global dsu
    a, b = find(a), find(b)
    if a == b: return False
    if dsu[a] > dsu[b]: a, b = b, a
    dsu[a] += dsu[b]
    dsu[b] = a
    return True

def solve():
    n, m = map(int, input().split())
    input()

    global dsu
    dsu = [-1] * n

    n_comps = n
    for i in range(m):
        l1, i1, l2, i2 = map(int, input().split())
        if join(l1-1, l2-1):
            n_comps -= 1
        
    if n_comps == 1:
        print("YES")
    else:
        print("NO")

t = int(input())
for ti in range(t):
    solve()