for i in range(int(input())):
    n,m=[int(num) for num in input().split()]
    x=list(map(int,input().split()))
    y=list(map(int,input().split()))
    c1=1
    for i in range(0,len(x)):
        if x[i] in y:
            c1=0
            print('YES')
            print(1,x[i])
            break
        else:
            continue
    if c1==1:
        print('NO')        
