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(" ")))
    chk=0
    for x in a:
        if x in b:
            print("YES")
            print(1,x)
            chk=1
            break;
    if chk==1:
        continue;
    else:
        print("NO")
        
    