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