def solve():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    for i in range(1,1001):
        ina,inb = False,False
        for j in a:
            if j==i:
                ina=True
                break
        for j in b:
            if j==i:
                inb=True
        if ina and inb:
            print("YES")
            print(1,i)
            return
    print("NO")

for _ in range(int(input())):
    solve()

