a=int(input())
for i in range(a):
    p,q=map(int,input().split())
    from collections import *
    al=defaultdict(int)
    z=list(map(int,input().split()))
    m=list(map(int,input().split()))
    flag=0
    for i in range(len(z)):
        if(al[z[i]]==0):
            al[z[i]]=1
    for i in range(len(m)):
        if(al[m[i]]==1):
            print('YES')
            print(1,m[i])
            flag=1
            break;
    if(flag):
        continue;
    else:
        print('NO')
