from sys import *
input = stdin.readline

for _ in range(int(input())):
    
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    
    c = []
    for i in a:
        if(i in b):
            c.append(i)
            break
    
    if(len(c) == 1):
        stdout.write("YES\n")
        stdout.write("1 "+str(c[0])+'\n')
    else:
        stdout.write("NO\n")