for _ in range(int(input())):
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x,s = 0,0
    for i in a:
        if i in b:
            x = i
            break
        else:
            s+=1
    if x>0:
        print('YES')
        print(1,x)
    else:
        print('NO')
