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