for _ in range(int(input())):
    n,m=map(int,input().split())
    lis1=list(map(int,input().split()))
    lis2=list(map(int,input().split()))
    flag=0
    for i in range(n):
        for j in range(m):
            if lis1[i]==lis2[j]:
                print("YES")
                print('1',lis1[i],sep=' ')
                flag=1
                break
        if flag==1:
            break
    if flag==0:
        print("NO")
