t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    arr=[int(x) for x in input().split()]
    arr1=[int(x) for x in input().split()]
    arr=set(arr)
    arr1=set(arr1)
    for each in arr:
        if each in arr1:
            print("YES")
            print("1",each)
            break
    else:
        print("NO")