# Pradnyesh Choudhari
# Tue Jul 21 20:01:51 2020

for i in range(int(input())):
    a, b = map(int, input().split())
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    l3 = list(set(l1).intersection(l2))
    if len(l3)>=1:
        print('YES')
        print(1, l3[0])
    else:
        print('NO')

