t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for elem in a:
        found = False
        if elem in b:
            print("YES")
            print(1, elem)
            found = True
            break
    if not found:
        print("NO")