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