for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans="NO"
    for i in range(n):
        if a[i] in b:
            ans="YES"
            print("YES")
            print(1,a[i])
            break
    if ans=="NO":
        print(ans)