t = int(input())
while(t>0):
    t-=1
    n,m = input().split()
    n=int(n)
    m=int(m)
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    x=0
    for i in a:
        if(i in b):
            print("YES")
            print("1 ", i)
            x=1
            break
    if(x==0):
        print("NO")