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