t = int(input())
while t>0:
    n,m = map(int,input().split())
    arr1 = list(map(int,input().split()))
    arr2 = list(map(int,input().split()))
    res = 'NO'
    number =-1
    for i in arr1:
        if i in arr2:
            res = 'YES'
            number =i
    if number==-1:
        print('NO')
    else:
        print('YES')
        print('1',number)
    t-=1
