for _ in range(int(input())):
    n,m=map(int,input().split())
    arr=list(map(int,input().split()))
    brr=list(map(int,input().split()))
    flag=0
    for item in brr:
        if item in arr:
            print("YES",1,item)
            flag=1
            break
    if flag==0:
        print('NO')