for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    for i in a:
        if i in b:
            c=1
            break
        else:
            c=0
            continue
    if c==1:
        print("YES\n1 {}".format(i))
    else:
        print("NO")