def solve(arr,arr2):
    for i in arr:
        if i in arr2:
            print("YES")
            print(1,end=" ")
            print(i)
            return
    print("NO")


for _ in range(int(input())):
    n,m = map(int,input().split())
    arra = list(map(int,input().split()))
    arrb = list(map(int,input().split()))
    solve(arra,arrb)