# Arup Guha
# 7/23/2025
# Solution to 2025 SI@UCF Competitive Programming Camp Contest #5 Problem: Good Groupings

nC = int(input())

# Process cases.
for loop in range(nC):

    toks = input().split()
    nAdults = int(toks[0])
    queries = int(toks[1])

    # Make set of adults.
    adults = set()
    for i in range(nAdults):
        adults.add(input().strip())

    # Go through queries.
    for i in range(queries):

        # Read figure out group size.
        toks = input().split()
        gSize = len(toks)-1

        # Slow but I just do it once so okay.
        del toks[0]
        hasAdult = False

        # See if adult in the group
        for x in toks:
            if x in adults:
                hasAdult = True

        # Output accordingly.
        if hasAdult and gSize >=3:
            print("Good")
        else:
            print("Not good")
        
