

for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    h={}
    out=0
    p=0
    for i in b:
        if(i not in h):h[i]=1
    for i in a:
        if(i in h):p=1;out=i;break    
    if(p==0):
        print("NO")
    else:
        print("YES")
        print(1,out)    