t = int(input())
while t:
    t-=1
    n,m = map(int,input().split())
    l1 = set(map(int,input().split()))
    l2 = set(map(int,input().split()))
    ls = list(l1.intersection(l2))
    if len(ls)>0:
        print("YES")
        print(1, ls[0])
    else:
        print("NO")