for _ in range(int(input())):
    n,m=[int(i) for i in input().split()]
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    s=set()
    for i in a:
        s.add(i)
    check=True
    for i in b:
        if i in s:
            print("YES")
            print("1",i)
            check=False
            break
    if check:
        print("NO")