import math
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    a = list(map(int, input().split()))
    b= list(map(int, input().split()))
    f=True
    for i in range(len(a)):
        for j in range(len(b)):
            if a[i]==b[j]:
                print('YES')
                print(1,'', a[i])
                f=False
                break
        if f==False: 
            break    
    if f :
        print('NO')        