for _ in range(int(input())):
    a,b=map(int,input().split())
    r1,r2=[set(map(int,input().split())) for _ in range(2)]
    for u in r1:
        if u in r2:
            print("YES")
            print(1,u)
            break
    else:
        print("NO")