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

