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