from collections import Counter
for _ in range(int(input())):
    n,m = map(int,input().split())
    A = Counter(list(map(int,input().split())))
    B = Counter(list(map(int,input().split())))
    ans = -1
    for i in A:
        if ans!=-1:break
        if i in B:
            ans = i
            break
    if ans==-1:
        print('NO')
    else:
        print('YES')
        print(1,ans)