for _ in range(int(input())):
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    cnt = [0 for i in range(1001)]
    for i in B:
        cnt[i]+=1
    ans = -1
    for i in A:
        if(cnt[i]>=1):
            ans = i
            break
    if(ans==-1):
        print("NO")
    else:
        print("YES")
        print(1,ans)
        

    