t = int(input())

while t:
    t-=1
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ok=False
    for aa in a:
        for bb in b:
            if aa==bb:
                print("YES")
                print(1,aa)
                ok=True
                break
        if ok:
            break
    if not ok:
        print("NO")
