t= int(input())
for _ in range(t):
    m,n = list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=[value for value in a if value in b]
    if(len(c) ==0):
        print('NO')
    else:
        print('YES')
        print('1',end=' ')
        print(c[0])