t = int(input())
for _ in range(t):
    n,m = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))
    B = list(map(int, input().split(' ')))
    x = set(A).intersection(set(B))
    if x:
        print("YES")
        print(1, end=" ")
        for i in x:
            print(i)
            break   
    else:
        print("NO")