for _ in range(int(input())):
    a,b=map(int,input().split())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    c=0
    for i in range(a):
        if la[i] in lb:
            c=la[i]
            break
    if c!=0:
        print("YES")
        print(1,c)
    else:
        print("NO")
