from collections import Counter
for i in range(int(input())):
    n,m=map(int,input().split())
    l=[int(i) for i in input().split()]
    m=[int(i) for i in input().split()]
    c=Counter(l)
    for i in m:
        if c.get(i,0):
            print('YES')
            print(1,i)
            break
    else:
        print('NO')