from sys import stdin

t = int(stdin.readline())
for _ in range(t):
    n, m = map(int, stdin.readline().split())
    an = list(map(int, stdin.readline().split()))
    am = list(map(int, stdin.readline().split()))
    found = False
    for i in an:
        for j in am:
            if i == j:
                print(f"YES\n1 {i}")
                found = True
                break
        if found: break
    if found: continue
    print("NO")
