for _ in range(int(input())):
    n,m=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    d=0
    for i in range(n):
        if l1[i] in l2:
            d=l1[i]
            break
    if d!=0:
        print("YES")
        print(1,d)
    else:
        print("NO")