for _ in range(int(input())):
    
    n,m=map(int,(input().split()))
    num1=set([int(x) for x in input().split()])
    num2=set([int(x) for x in input().split()])
    if (num1 & num2):
        print("YES")
        print("1 "+str(list(num1 & num2)[0]))
    else:
        print("NO")
    