for _ in range(int(input())):
    n,m=[int(x) for x in input().split()]
    a=[int(x) for x in input().split()]
    b=[int(x) for x in input().split()]
    d=-1
    for i in range(n):
        for j in range(m):
            if(a[i]==b[j]):
                d=a[i]
    if(d==-1):
        print("NO")
    else:
        print("YES")
        print(1,d)
