t = int(input())
for i in range(t):
    n,m = input().split(' ')
    a = input().split(' ')
    b = input().split(' ')
    check = False
    for j in a:
        for k in b:
            if(j==k):
                print("YES")
                print("1",j)
                check = True
                break
        if(check):
            break
    if(not check):
        print("NO")

