import sys
input = sys.stdin.readline

for T in range(int(input())) :
    n , m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    d= {}
    for i in range(n) :
        d[a[i]] =1

    ans = -1
    for i in range(m) :
        if(d.get(b[i] ,0)):
            ans = b[i]
            break
    if(ans == -1):
        print("NO")
    else :
        print("YES")
        print(1,ans)
