t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    arr1=list(map(int,input().split()))
    arr2=list(map(int,input().split()))
    b=0
    for a in arr1:
        if a in arr2:
            print('YES')
            print('1 '+str(a))
            b=1
            break
    if b==0:
        print('NO')