t=int(input())
for i in range(t):
    a,b=map(int,input().split())
    l1=set(input().split())
    l2=set(input().split())
    if len(l1&l2)==0:
        print("NO")
    else:
        print("YES")
        print(1,list(l1 &l2)[0])