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