for I in range(int(input())):
    n,m = map(int,input().split())

    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    dic = {}
    flag = 'NO'
    for num in a:
        dic[num]=1

    for num in b:
        if num in dic:
            flag=num
            break

    if flag=='NO':
        print(flag)
    else:
        print('YES')
        print(1,flag)
            

    
