# cook your dish here
T=int(input())
for _ in range(T):
    n1,n2=list(map(int,input().split()))
    s1=list(map(int,input().split()))
    s2=list(map(int,input().split()))
    flag=0
    for i in range(n1):
        if s1[i] in s2:
            print('YES')
            print(1,s1[i])
            flag=1
            break
    if flag==0:
        print('NO')
    