t=int(input())

for _ in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=set(map(int,input().split()))
    ans=0
    flg=0
    for i in range(n):
        if a[i] in b:
            flg=1
            ans=a[i]
            break
    if flg:
        print('YES')
        print(1,ans)
    else:
        print('NO')