t = int(input())
for _ in range(t):
    n,m = map(int,input().split())
    a = set(list(map(int,input().split())))
    b = set(list(map(int,input().split())))
    if a.intersection(b):
        for num in a:
            if num in b:
                print("YES")
                print(f"{1} {num}")
                break
    else:
        print("NO")