a=int(input())
for i in range(a):
    n,m=map(int,input().split())
    a=set(map(int,input().split()))
    b=set(map(int,input().split()))
    s=a&b
    a=list(a)
    b=list(b)
    if len(s)!=0:
       print('YES')
       for j in s:
           print('1',j)
           break
    else:
       print('NO')
